32 #ifndef _GLIBCXX_PARALLEL_RANDOM_NUMBER_H
33 #define _GLIBCXX_PARALLEL_RANDOM_NUMBER_H 1
39 namespace __gnu_parallel
48 double _M_supremum_reciprocal;
49 double _M_rand_sup_reciprocal;
58 __scale_down(uint64_t __x,
60 uint64_t ,
double _M_supremum_reciprocal)
62 uint64_t _M_supremum,
double )
65 #if _GLIBCXX_SCALE_DOWN_FPU
66 return uint32_t(__x * _M_supremum_reciprocal);
68 return static_cast<uint32_t
>(__x % _M_supremum);
75 : _M_mt(0), _M_supremum(0x100000000ULL),
76 _M_rand_sup(1ULL << std::numeric_limits<uint32_t>::digits),
77 _M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)),
78 _M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)),
79 __cache(0), __bits_left(0) { }
86 : _M_mt(__seed), _M_supremum(_M_supremum),
87 _M_rand_sup(1ULL << std::numeric_limits<uint32_t>::digits),
88 _M_supremum_reciprocal(double(_M_supremum) / double(_M_rand_sup)),
89 _M_rand_sup_reciprocal(1.0 / double(_M_rand_sup)),
90 __cache(0), __bits_left(0) { }
95 {
return __scale_down(_M_mt(), _M_supremum, _M_supremum_reciprocal); }
102 return __scale_down(_M_mt(), local_supremum,
103 double(local_supremum * _M_rand_sup_reciprocal));
111 unsigned long __res = __cache & ((1 << __bits) - 1);
112 __cache = __cache >> __bits;
113 __bits_left -= __bits;
114 if (__bits_left < 32)
116 __cache |= ((uint64_t(_M_mt())) << __bits_left);
uint32_t operator()()
Generate unsigned random 32-bit integer.
_RandomNumber(uint32_t __seed, uint64_t _M_supremum=0x100000000ULL)
Constructor.
#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.
uint32_t operator()(uint64_t local_supremum)
Generate unsigned random 32-bit integer in the interval [0,local_supremum).
_RandomNumber()
Default constructor. Seed with 0.
Random number generator, based on the Mersenne twister.
mersenne_twister_engine< uint_fast32_t, 32, 624, 397, 31, 0x9908b0dfUL, 11, 0xffffffffUL, 7, 0x9d2c5680UL, 15, 0xefc60000UL, 18, 1812433253UL > mt19937
unsigned long __genrand_bits(int __bits)
Generate a number of random bits, run-time parameter.
Basic types and typedefs. This file is a GNU parallel extension to the Standard C++ Library...