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