Vita
random.cc
Go to the documentation of this file.
1
13#include "kernel/random.h"
14
15namespace vita
16{
17
18namespace random
19{
20
28
42void seed(unsigned s)
43{
44 engine.seed(s);
45}
46
51{
52 std::random_device rd;
53 seed(rd());
54}
55
65unsigned ring(unsigned base, unsigned width, unsigned n)
66{
67 Expects(base < n);
68 Expects(width);
69 Expects(n > 1);
70
71 if (width >= n)
72 return random::between(0u, n);
73
74 const auto min_val(base + n - width / 2);
75
76 return (min_val + random::between(0u, width)) % n;
77}
78
79} // namespace random
80} // namespace vita
base_t base(const value_t &v)
A simple shortcut for casting an value_t to base_t.
Definition: real.h:49
The main namespace for the project.
unsigned ring(unsigned base, unsigned width, unsigned n)
Returns a random number in a modular arithmetic system.
Definition: random.cc:65
void seed(unsigned s)
Initalizes the random number generator.
Definition: random.cc:42
engine_t engine
The shared random engine generator.
Definition: random.cc:27
void randomize()
Sets the shared engine to an unpredictable state.
Definition: random.cc:50
vigna::xoshiro256ss engine_t
xoshiro256** (XOR/shift/rotate) is an all-purpose, rock-solid generator (not a cryptographically secu...
Definition: random.h:34