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 {
10inline namespace v1 {
11
12inline char32_t random_char() noexcept
13{
14 static auto rand = std::mt19937();
15 static auto size_dist = std::uniform_int_distribution(0, 99);
16 static auto ascii_dist = std::uniform_int_distribution(0, 0x7f);
17 static auto latin_dist = std::uniform_int_distribution(0x80, 0x7ff);
18 static auto basic_dist = std::uniform_int_distribution(0x800, 0xf7ff); // without surrogates
19 static auto full_dist = std::uniform_int_distribution(0x01'0000, 0x10'ffff);
20
21 auto s = size_dist(rand);
22 if (s < 90) {
23 return char_cast<char32_t>(ascii_dist(rand));
24
25 } else if (s < 95) {
26 return char_cast<char32_t>(latin_dist(rand));
27
28 } else if (s < 98) {
29 auto c = char_cast<char32_t>(basic_dist(rand));
30 if (c >= 0xd800 and c < 0xe000) {
31 c += 0x800;
32 }
33 return c;
34
35 } else {
36 return char_cast<char32_t>(full_dist(rand));
37 }
38}
39
40}} // namespace hi::inline v1
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
T rand(T... args)