15 #ifndef STXXL_COMMON_RAND_HEADER
16 #define STXXL_COMMON_RAND_HEADER
27 #elif STXXL_BOOST_RANDOM
28 #include <boost/random.hpp>
61 return operator () () % N;
107 : m_rnd32(seed), m_pos(4)
117 return ((
uint8*)&m_value)[m_pos];
134 return (
double(rnd32()) * (0.5 / 0x80000000));
139 #pragma warning(push)
140 #pragma warning(disable:4512) // assignment operator could not be generated
151 typedef std::default_random_engine gen_type;
152 mutable gen_type gen;
153 typedef std::uniform_real_distribution<> uni_type;
154 mutable uni_type uni;
160 #elif STXXL_BOOST_RANDOM
161 typedef boost::minstd_rand base_generator_type;
162 base_generator_type generator;
163 boost::uniform_real<> uni_dist;
164 mutable boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni;
170 uni.engine().seed(seed);
173 mutable unsigned short state48[3];
192 unsigned short temp[2];
194 static const unsigned short _mult[3] = { 0xe66d, 0xdeec, 0x0005 };
195 static const unsigned short _add = 0x000b;
197 accu = (
unsigned long)_mult[0] * (
unsigned long)xseed[0]
198 + (
unsigned long)_add;
199 temp[0] = (
unsigned short)accu;
200 accu >>=
sizeof(
unsigned short) * 8;
201 accu += (
unsigned long)_mult[0] * (
unsigned long)xseed[1]
202 + (
unsigned long)_mult[1] * (
unsigned long)xseed[0];
203 temp[1] = (
unsigned short)accu;
204 accu >>=
sizeof(
unsigned short) * 8;
205 accu += _mult[0] * xseed[2] + _mult[1] * xseed[1] + _mult[2] * xseed[0];
208 xseed[2] = (
unsigned short)accu;
215 return ldexp((
double)xseed[0], -48)
216 + ldexp((
double)xseed[1], -32)
217 + ldexp((
double)xseed[2], -16);
225 state48[0] = (
unsigned short)(seed & 0xffff);
226 state48[1] = (
unsigned short)(seed >> 16);
237 #elif STXXL_BOOST_RANDOM
240 return _erand48(state48);
246 template <
class UniformRGen = random_uniform_fast>
258 return static_cast<value_type>(uniform() * double(N));
274 return static_cast<value_type>(uniform() * (18446744073709551616.));
280 return static_cast<value_type>(uniform() * double(N));
285 #pragma warning(pop) // assignment operator could not be generated
292 #endif // !STXXL_COMMON_RAND_HEADER
random_number64(unsigned seed=0)
Uniform [0, N) pseudo-random generator.
random_uniform_slow uniform
unsigned long long int uint64
unsigned get_next_seed()
get a seed value for prng initialization, subsequent calls return a sequence of different values ...
random_number32_r m_rnd32
Fast uniform [0, 255] pseudo-random generator with period 2^8, random bits: 8 (one byte)...
random_number32_r(unsigned seed=0)
#define STXXL_BEGIN_NAMESPACE
void srandom_number32(unsigned seed=0)
Set a seed value for random_number32.
Fast uniform [0, 2^32) pseudo-random generator with period 2^32, random bits: 32. Reentrant variant o...
Fast uniform [0, 2^32) pseudo-random generator with period 2^32, random bits: 32. ...
random_number(unsigned seed=0)
random_number8_r(unsigned seed=0)
#define STXXL_END_NAMESPACE
Slow and precise uniform [0, 2^64) pseudo-random generator.