HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
random_char.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <random>
8
9namespace hi::inline v1 {
10
11inline char32_t random_char() noexcept
12{
13 static auto rand = std::mt19937();
14 static auto size_dist = std::uniform_int_distribution(0, 99);
15 static auto ascii_dist = std::uniform_int_distribution(0, 0x7f);
16 static auto latin_dist = std::uniform_int_distribution(0x80, 0x7ff);
17 static auto basic_dist = std::uniform_int_distribution(0x800, 0xf7ff); // without surrogates
18 static auto full_dist = std::uniform_int_distribution(0x01'0000, 0x10'ffff);
19
20 auto s = size_dist(rand);
21 if (s < 90) {
22 return char_cast<char32_t>(ascii_dist(rand));
23
24 } else if (s < 95) {
25 return char_cast<char32_t>(latin_dist(rand));
26
27 } else if (s < 98) {
28 auto c = char_cast<char32_t>(basic_dist(rand));
29 if (c >= 0xd800 and c < 0xe000) {
30 c += 0x800;
31 }
32 return c;
33
34 } else {
35 return char_cast<char32_t>(full_dist(rand));
36 }
37}
38
39} // namespace hi::inline v1
T rand(T... args)