libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <random>
14#include <cstdint>
15#include <cstddef>
16#include <promeki/namespace.h>
17
18PROMEKI_NAMESPACE_BEGIN
19
20class Buffer;
21class Error;
22
52class Random {
53 public:
66 static Error trueRandom(uint8_t *buf, size_t bytes);
67
72 static Random &global();
73
77 Random();
78
83 explicit Random(uint64_t seed);
84
89 void seed(uint64_t seed);
90
97 int randomInt(int min, int max);
98
105 int64_t randomInt64(int64_t min, int64_t max);
106
113 double randomDouble(double min, double max);
114
121 float randomFloat(float min, float max);
122
129 double randomNormalDouble(double mean, double stddev);
130
137 float randomNormalFloat(float mean, float stddev);
138
148 double randomExponentialDouble(double lambda);
149
155 Buffer randomBytes(size_t count);
156
161 bool randomBool();
162
163 // -- UniformRandomBitGenerator concept --
164 //
165 // The four members below let Random be passed directly to
166 // standard algorithms that take a URBG, e.g. @c std::shuffle
167 // and @c std::sample, and to the constructors of any
168 // standard distribution (@c std::normal_distribution and
169 // friends).
170
172 using result_type = std::mt19937_64::result_type;
173
175 static constexpr result_type min() { return std::mt19937_64::min(); }
176
178 static constexpr result_type max() { return std::mt19937_64::max(); }
179
181 result_type operator()() { return _engine(); }
182
183 private:
184 std::mt19937_64 _engine;
185};
186
187PROMEKI_NAMESPACE_END
188
189#endif // PROMEKI_ENABLE_CORE