|
| Rng (Rng const &)=delete |
|
Rng & | operator= (Rng const &)=delete |
|
| Rng (Rng &&) noexcept=default |
|
Rng & | operator= (Rng &&) noexcept=default |
|
| ~Rng () noexcept=default |
|
| Rng () |
| Creates a new Random generator with random seed. More...
|
|
| Rng (uint64_t seed) noexcept |
|
| Rng (uint64_t x, uint64_t y) noexcept |
|
| Rng (std::vector< uint64_t > const &data) |
|
Rng | copy () const noexcept |
|
uint64_t | operator() () noexcept |
| Produces a 64bit random value. This should be very fast, thus it is marked as inline. In my benchmark, this is ~46 times faster than std::default_random_engine for producing 64bit random values. It seems that the fastest std contender is std::mt19937_64 . Still, this RNG is 2-3 times as fast. More...
|
|
uint32_t | bounded (uint32_t range) noexcept |
|
double | uniform01 () noexcept |
|
template<typename Container > |
void | shuffle (Container &container) noexcept |
|
std::vector< uint64_t > | state () const |
|
An extremely fast random generator. Currently, this implements RomuDuoJr, developed by Mark Overton. Source: http://www.romu-random.org/
RomuDuoJr is extremely fast and provides reasonable good randomness. Not enough for large jobs, but definitely good enough for a benchmarking framework.
- Estimated capacity: bytes
- Register pressure: 4
- State size: 128 bits
This random generator is a drop-in replacement for the generators supplied by <random>
. It is not cryptographically secure. It's intended purpose is to be very fast so that benchmarks that make use of randomness are not distorted too much by the random generator.
Rng also provides a few non-standard helpers, optimized for speed.
zeroerr::Rng::Rng |
( |
uint64_t |
seed | ) |
|
|
explicitnoexcept |
Creates a new Rng that is seeded with a specific seed. Each Rng created from the same seed will produce the same randomness sequence. This can be useful for deterministic behavior.
embed:rst
.. note::
The random algorithm might change between nanobench releases. Whenever a faster and/or
better random generator becomes available, I will switch the implementation.
As per the Romu paper, this seeds the Rng with splitMix64 algorithm and performs 10 initial rounds for further mixing up of the internal state.
- Parameters
-
seed | The 64bit seed. All values are allowed, even 0. |
uint32_t zeroerr::Rng::bounded |
( |
uint32_t |
range | ) |
|
|
inlinenoexcept |
Generates a random number between 0 and range (excluding range).
The algorithm only produces 32bit numbers, and is slightly biased. The effect is quite small unless your range is close to the maximum value of an integer. It is possible to correct the bias with rejection sampling (see here, but this is most likely irrelevant in practices for the purposes of this Rng.
See Daniel Lemire's blog post A fast alternative to the modulo reduction
- Parameters
-
range | Upper exclusive range. E.g a value of 3 will generate random numbers 0, 1, 2. |
- Returns
- uint32_t Generated random values in range [0, range).