Go to the source code of this file.
|
namespace | vita |
| The main namespace for the project.
|
|
|
using | vita::random::engine_t = vigna::xoshiro256ss |
| xoshiro256** (XOR/shift/rotate) is an all-purpose, rock-solid generator (not a cryptographically secure generator). More...
|
|
|
enum class | distribution { uniform
, normal
} |
|
|
template<class T > |
std::enable_if_t< std::is_floating_point_v< T >, T > | vita::random::between (T min, T sup) |
| A specialization for floating point values of the random::between(T, T) template function. More...
|
|
template<class T > |
std::enable_if_t< std::is_integral_v< T >, T > | vita::random::between (T min, T sup) |
| Picks up a random integer value uniformly distributed in the set of integers {min, min+1, ..., sup-1} . More...
|
|
template<class T > |
std::enable_if_t< std::is_enum_v< T >, T > | vita::random::between (T min, T sup) |
|
bool | vita::random::boolean (double=0.5) |
|
template<class C > |
C::value_type & | vita::random::element (C &c) |
|
template<class C > |
const C::value_type & | vita::random::element (const C &c) |
|
template<class T > |
T | vita::random::ephemeral (distribution d, T p1, T p2) |
| Used for ephemeral random constant generation. More...
|
|
template<class T > |
T | vita::random::in (range_t< T > r) |
| Uniformly extracts a random value in a range. More...
|
|
void | vita::random::randomize () |
| Sets the shared engine to an unpredictable state. More...
|
|
unsigned | vita::random::ring (unsigned base, unsigned width, unsigned n) |
| Returns a random number in a modular arithmetic system. More...
|
|
void | vita::random::seed (unsigned s) |
| Initalizes the random number generator. More...
|
|
template<class T > |
T | vita::random::sup (T) |
|
- Copyright
- Copyright (C) 2011-2024 EOS di Manlio Morini.
- License\n
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/
Definition in file random.h.
◆ engine_t
xoshiro256** (XOR/shift/rotate) is an all-purpose, rock-solid generator (not a cryptographically secure generator).
It has excellent (sub-ns) speed, a state space (256 bits) that is large enough for any parallel application, and it passes all tests we are aware of.
Definition at line 34 of file random.h.
◆ distribution
enum class vita::random::distribution |
|
strong |
◆ between() [1/3]
template<class T >
std::enable_if_t< std::is_floating_point_v< T >, T > vita::random::between |
( |
T |
min, |
|
|
T |
sup |
|
) |
| |
A specialization for floating point values of the random::between(T, T)
template function.
- Parameters
-
[in] | min | minimum random number |
[in] | sup | upper bound |
- Returns
- a random
double
in the [min;sup[
range
- See also
- For further details:
Definition at line 85 of file random.h.
◆ between() [2/3]
template<class T >
std::enable_if_t< std::is_integral_v< T >, T > vita::random::between |
( |
T |
min, |
|
|
T |
sup |
|
) |
| |
Picks up a random integer value uniformly distributed in the set of integers {min, min+1, ..., sup-1}
.
- Parameters
-
[in] | min | minimum random number |
[in] | sup | upper bound |
- Returns
- a random number in the
[min;sup[
range
- Note
- Contrary to boost usage this function does not take a closed range. Instead it takes a half-open range (C++ usage and same behaviour of the real number distribution).
Definition at line 108 of file random.h.
◆ between() [3/3]
template<class T >
std::enable_if_t< std::is_enum_v< T >, T > vita::random::between |
( |
T |
min, |
|
|
T |
sup |
|
) |
| |
◆ boolean()
bool vita::random::boolean |
( |
double |
p | ) |
|
|
inline |
- Parameters
-
[in] | p | a probability ([0;1] range) |
- Returns
true
p%
times
- Note
bool
values are produced according to the Bernoulli distribution.
Definition at line 183 of file random.h.
◆ element() [1/2]
template<class C >
C::value_type & vita::random::element |
( |
C & |
c | ) |
|
- Parameters
-
- Returns
- a random element of container
c
Definition at line 168 of file random.h.
◆ element() [2/2]
template<class C >
const C::value_type & vita::random::element |
( |
const C & |
c | ) |
|
◆ ephemeral()
template<class T >
T vita::random::ephemeral |
( |
distribution |
d, |
|
|
T |
p1, |
|
|
T |
p2 |
|
) |
| |
Used for ephemeral random constant generation.
- Parameters
-
[in] | d | type of distribution |
[in] | p1 | minimum for uniform distribution; mean for normal distribution |
[in] | p2 | maximum for uniform distribution, standard deviation for normal distribution |
- Returns
- a random number distributed according to distribution
d
Definition at line 58 of file random.h.
◆ in()
template<class T >
T vita::random::in |
( |
range_t< T > |
r | ) |
|
Uniformly extracts a random value in a range.
- Parameters
-
- Returns
- a random value in range
r
Definition at line 132 of file random.h.
◆ randomize()
void vita::random::randomize |
( |
| ) |
|
Sets the shared engine to an unpredictable state.
Definition at line 50 of file random.cc.
◆ ring()
unsigned vita::random::ring |
( |
unsigned |
base, |
|
|
unsigned |
width, |
|
|
unsigned |
n |
|
) |
| |
Returns a random number in a modular arithmetic system.
- Parameters
-
[in] | base | a base number |
[in] | width | maximum distance from the base number |
[in] | n | modulus |
- Returns
- a random number in the
[base - width/2, base + width/2] mod n
interval
Definition at line 65 of file random.cc.
◆ seed()
void vita::random::seed |
( |
unsigned |
s | ) |
|
Initalizes the random number generator.
- Parameters
-
[in] | s | the seed for the random number generator |
The seed is used to initalize the random number generator. With the same seed the numbers produced will be the same every time the program is run.
- Note
- A common method to seed a PRNG is using the current time (
std::time(0)
). It works... but the preferred way in Vita is the randomize
method (which is based on std::random_device
).
Definition at line 42 of file random.cc.
◆ sup()
template<class T >
T vita::random::sup |
( |
T |
sup | ) |
|
- Parameters
-
- Returns
- a random number in the [0;sup[ range
- Note
- This is a shortcut for:
between<T>(0, sup)
Definition at line 144 of file random.h.