the generator \( X_{n+1} = ( a X_n + c ) \bmod m \), \( m = 0 \) meaning \( 2^{64} \)
More...
#include <ADS/numeric/RandomNumbers.h>
|
| using | result_type = std::uint64_t |
| | the type of the numbers
|
|
| | LinearCongruential (std::uint64_t a, std::uint64_t c, std::uint64_t m, std::uint64_t seed) |
| | the generator of multiplier \( a \), increment \( c \) and modulus \( m \), from \( X_0 = \mathit{seed} \)
|
| std::uint64_t | operator() (void) |
| | the next number \( X_{n+1} = ( a X_n + c ) \bmod m \), by mulMod() and an addition that does not overflow (section 3.2.1 of Knuth)
|
| std::uint64_t | min (void) const |
| | the least number, 1 if \( c = 0 \) as in std::linear_congruential_engine (0 is then a fixed point, which the multiplicative generators, as minstd(), never reach), 0 otherwise
|
| std::uint64_t | max (void) const |
| | the largest number, \( m - 1 \)
|
| std::uint64_t | period (std::uint64_t limit) const |
| | the period, by walking the sequence, when it is at most \( \mathit{limit} \); 0 otherwise
|
|
| static LinearCongruential | minstd (std::uint64_t seed=1) |
| | the generator of Park and Miller, \( a = 16807 \), \( c = 0 \), \( m = 2^{31} - 1 \)
|
| static LinearCongruential | mmix (std::uint64_t seed=1) |
| | the generator of Knuth for MMIX, \( m = 2^{64} \)
|
the generator \( X_{n+1} = ( a X_n + c ) \bmod m \), \( m = 0 \) meaning \( 2^{64} \)
◆ result_type
◆ LinearCongruential()
| ADS::LinearCongruential::LinearCongruential |
( |
std::uint64_t | a, |
|
|
std::uint64_t | c, |
|
|
std::uint64_t | m, |
|
|
std::uint64_t | seed ) |
the generator of multiplier \( a \), increment \( c \) and modulus \( m \), from \( X_0 = \mathit{seed} \)
- Precondition
- \( m = 0 \), or \( a < m \), \( c < m \) and \( \mathit{seed} < m \)
◆ max()
| std::uint64_t ADS::LinearCongruential::max |
( |
void | | ) |
const |
|
inlinenodiscard |
the largest number, \( m - 1 \)
◆ min()
| std::uint64_t ADS::LinearCongruential::min |
( |
void | | ) |
const |
|
inlinenodiscard |
the least number, 1 if \( c = 0 \) as in std::linear_congruential_engine (0 is then a fixed point, which the multiplicative generators, as minstd(), never reach), 0 otherwise
◆ minstd()
the generator of Park and Miller, \( a = 16807 \), \( c = 0 \), \( m = 2^{31} - 1 \)
◆ mmix()
the generator of Knuth for MMIX, \( m = 2^{64} \)
◆ operator()()
| std::uint64_t ADS::LinearCongruential::operator() |
( |
void | | ) |
|
the next number \( X_{n+1} = ( a X_n + c ) \bmod m \), by mulMod() and an addition that does not overflow (section 3.2.1 of Knuth)
◆ period()
| std::uint64_t ADS::LinearCongruential::period |
( |
std::uint64_t | limit | ) |
const |
|
nodiscard |
the period, by walking the sequence, when it is at most \( \mathit{limit} \); 0 otherwise
In pseudocode (the cycle detection of Brent, beyond the book), the tortoise moved to the hare at each power of 2:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{period}( \mathit{limit} ) \cr
2 & \quad t \gets X_1;\ h \gets X_2;\ \mathit{power} \gets 1;\ \lambda
\gets 1 \cr
3 & \quad \textbf{while}\ t \ne h\ \textbf{do} \cr
4 & \qquad \textbf{if}\ \mathit{power} = \lambda\ \textbf{then}\ t \gets
h;\ \mathit{power} \gets 2 \mathit{power};\ \lambda \gets 0 \cr
5 & \qquad h \gets \text{the next number};\ \lambda \gets \lambda + 1 \cr
6 & \qquad \textbf{if}\ \lambda > \mathit{limit}\ \textbf{then return}
\ 0 \cr
7 & \quad \textbf{return}\ \lambda
\end{array}}
\]
The documentation for this class was generated from the following file: