HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
src
hikogui
char_maps
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
11
hi_export_module(hikogui.char_maps.random_char);
12
13
hi_export
namespace
hi
{
14
inline
namespace
v1
{
15
16
hi_inline
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
v1
DOXYGEN BUG.
Definition
algorithm_misc.hpp:20
hi
The HikoGUI namespace.
Definition
recursive_iterator.hpp:15
hi::v1::narrow_cast
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition
cast.hpp:378
std::mt19937
std::rand
T rand(T... args)
std::uniform_int_distribution
Generated on Mon Apr 22 2024 12:51:58 for HikoGUI by
1.10.0