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 "../macros.hpp"
8
#include <random>
9
10
namespace
hi
{
11
inline
namespace
v1
{
12
13
inline
char32_t
random_char()
noexcept
14
{
15
static
auto
rand
=
std::mt19937
();
16
static
auto
size_dist
=
std::uniform_int_distribution
(0, 99);
17
static
auto
ascii_dist
=
std::uniform_int_distribution
(0, 0x7f);
18
static
auto
latin_dist
=
std::uniform_int_distribution
(0x80, 0x7ff);
19
static
auto
basic_dist
=
std::uniform_int_distribution
(0x800, 0xf7ff);
// without surrogates
20
static
auto
full_dist
=
std::uniform_int_distribution
(0x01'0000, 0x10'ffff);
21
22
auto
s =
size_dist
(rand);
23
if
(s < 90) {
24
return
char_cast<char32_t>
(
ascii_dist
(rand));
25
26
}
else
if
(s < 95) {
27
return
char_cast<char32_t>
(
latin_dist
(rand));
28
29
}
else
if
(s < 98) {
30
auto
c =
char_cast<char32_t>
(
basic_dist
(rand));
31
if
(c >= 0xd800
and
c < 0xe000) {
32
c += 0x800;
33
}
34
return
c;
35
36
}
else
{
37
return
char_cast<char32_t>
(
full_dist
(rand));
38
}
39
}
40
41
}}
// namespace hi::inline v1
v1
DOXYGEN BUG.
Definition
algorithm.hpp:16
hi
geometry/margins.hpp
Definition
lookahead_iterator.hpp:5
hi::v1::narrow_cast
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition
cast.hpp:377
std::mt19937
std::rand
T rand(T... args)
std::uniform_int_distribution
Generated on Mon Apr 22 2024 12:53:15 for HikoGUI by
1.10.0