32 #ifndef _GLIBCXX_PARALLEL_RANDOM_NUMBER_H
33 #define _GLIBCXX_PARALLEL_RANDOM_NUMBER_H 1
38 namespace __gnu_parallel
47 double supremum_reciprocal;
59 uint64 ,
double supremum_reciprocal)
61 uint64 supremum,
double )
64 #if _GLIBCXX_SCALE_DOWN_FPU
65 return uint32(x * supremum_reciprocal);
67 return static_cast<uint32>(x % supremum);
74 : mt(0), supremum(0x100000000ULL),
75 RAND_SUP(1ULL << (sizeof(
uint32) * 8)),
76 supremum_reciprocal(double(supremum) / double(RAND_SUP)),
77 RAND_SUP_REC(1.0 / double(RAND_SUP)),
78 cache(0), bits_left(0) { }
85 : mt(seed), supremum(supremum),
86 RAND_SUP(1ULL << (sizeof(
uint32) * 8)),
87 supremum_reciprocal(double(supremum) / double(RAND_SUP)),
88 RAND_SUP_REC(1.0 / double(RAND_SUP)),
89 cache(0), bits_left(0) { }
94 {
return scale_down(mt(), supremum, supremum_reciprocal); }
101 return scale_down(mt(), local_supremum,
102 double(local_supremum * RAND_SUP_REC));
110 unsigned long res = cache & ((1 << bits) - 1);
111 cache = cache >> bits;
115 cache |= ((
uint64(mt())) << bits_left);
unsigned int uint32
32-bit unsigned integer.
unsigned long long uint64
64-bit unsigned integer.
Basic types and typedefs. This file is a GNU parallel extension to the Standard C++ Library...
random_number()
Default constructor. Seed with 0.
uint32 operator()(uint64 local_supremum)
Generate unsigned random 32-bit integer in the interval [0,local_supremum).
uint32 operator()()
Generate unsigned random 32-bit integer.
Random number generator, based on the Mersenne twister.
mersenne_twister< unsigned long, 32, 624, 397, 31, 0x9908b0dful, 11, 7, 0x9d2c5680ul, 15, 0xefc60000ul, 18 > mt19937
unsigned long genrand_bits(int bits)
Generate a number of random bits, run-time parameter.
#define _GLIBCXX_SCALE_DOWN_FPU
Use floating-point scaling instead of modulo for mapping random numbers to a range. This can be faster on certain CPUs.
random_number(uint32 seed, uint64 supremum=0x100000000ULL)
Constructor.