|
ADS
Algorithms and Data Structures
|
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming), beyond the book: More...
#include "ADS/Contract.h"#include "ADS/numeric/NumberTheory.h"#include <algorithm>#include <cmath>#include <cstddef>#include <cstdint>#include <limits>#include <random>#include <utility>#include <vector>#include "ADS/numeric/impl/RandomNumbers.tpp"Go to the source code of this file.
Classes | |
| class | ADS::LinearCongruential |
| the generator \( X_{n+1} = ( a X_n + c ) \bmod m \), \( m = 0 \) meaning \( 2^{64} \) More... | |
| class | ADS::LinearCongruentialT< a, c, m > |
| the generator \( X_{n+1} = ( a X_n + c ) \bmod m \) of LinearCongruential with \( a , c , m \) fixed at compile time, \( m = 0 \) meaning \( 2^{64} \): a UniformRandomBitGenerator, as min() and max() are constant More... | |
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::MinStd = LinearCongruentialT< 16807 , 0 , 2147483647 > |
| the generator of Park and Miller, \( a = 16807 \), \( c = 0 \), \( m = 2^{31} - 1 \) | |
| using | ADS::Mmix |
| the generator of Knuth for MMIX, \( m = 2^{64} \) | |
Functions | |
| double | ADS::chiSquare (const std::vector< long > &Y, const std::vector< double > &p) |
| the chi-square statistic \( V \) of the counts \( Y \) against the probabilities \( p \) over \( n = \sum_s Y_s \) samples | |
| std::pair< double, double > | ADS::kolmogorovSmirnov (std::vector< double > U) |
| the statistics \( ( K^+_n , K^-_n ) \) of Kolmogorov and Smirnov of the numbers \( U \) in \( [ 0 , 1 ) \) against the uniform distribution, scaled by \( \sqrt{n} \) | |
| double | ADS::serialTest (const std::vector< double > &U, int d) |
| the chi-square statistic of the pairs \( ( U_{2j} , U_{2j+1} ) \) of numbers in \( [ 0 , 1 ) \) in \( d \times d \) cells, \( d^2 - 1 \) degrees of freedom | |
| double | ADS::spectralTest2 (std::uint64_t a, std::uint64_t m) |
| the \( \nu_2 \) of the spectral test of the generator of multiplier \( a \) and modulus \( m \) | |
| template<class T, class R> | |
| void | ADS::shuffle (std::vector< T > &A, R &g) |
| the vector \( A \) shuffled by \( g \), every permutation equally likely if \( g \) is uniform on its range | |
| template<class R> | |
| std::vector< std::size_t > | ADS::selectionSampling (std::size_t n, std::size_t N, R &g) |
| \( n \) of the \( N \) items \( 0 , \ldots , N - 1 \), in order, by one pass | |
| template<class T, class R> | |
| std::vector< T > | ADS::reservoirSampling (const std::vector< T > &S, std::size_t n, R &g) |
| \( n \) items from the sequence \( S \), as if it were a stream of unknown length; all of \( S \), in its order, when \( S \) has at most \( n \) items (a stream shorter than the sample) | |
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming), beyond the book:
The contracts [see Contract.h]: \( m \ge 1 \) and \( a , c < m \) for the generator, positive expected counts for the tests, \( n \le N \) for the samplings. The functions are defined in RandomNumbers.tpp.