15 #ifndef STXXL_COMMON_RAND_HEADER
16 #define STXXL_COMMON_RAND_HEADER
27 #elif STXXL_BOOST_RANDOM
28 #include <boost/random.hpp>
59 return operator () () % N;
105 : m_rnd32(seed), m_pos(4)
115 return ((
uint8*)&m_value)[m_pos];
132 return (
double(rnd32()) * (0.5 / 0x80000000));
137 #pragma warning(push)
138 #pragma warning(disable:4512) // assignment operator could not be generated
149 typedef std::default_random_engine gen_type;
150 mutable gen_type gen;
151 typedef std::uniform_real_distribution<> uni_type;
152 mutable uni_type uni;
158 #elif STXXL_BOOST_RANDOM
159 typedef boost::minstd_rand base_generator_type;
160 base_generator_type generator;
161 boost::uniform_real<> uni_dist;
162 mutable boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni;
168 uni.engine().seed(seed);
171 mutable unsigned short state48[3];
190 unsigned short temp[2];
192 static const unsigned short _mult[3] = { 0xe66d, 0xdeec, 0x0005 };
193 static const unsigned short _add = 0x000b;
195 accu = (
unsigned long)_mult[0] * (
unsigned long)xseed[0]
196 + (
unsigned long)_add;
197 temp[0] = (
unsigned short)accu;
198 accu >>=
sizeof(
unsigned short) * 8;
199 accu += (
unsigned long)_mult[0] * (
unsigned long)xseed[1]
200 + (
unsigned long)_mult[1] * (
unsigned long)xseed[0];
201 temp[1] = (
unsigned short)accu;
202 accu >>=
sizeof(
unsigned short) * 8;
203 accu += _mult[0] * xseed[2] + _mult[1] * xseed[1] + _mult[2] * xseed[0];
206 xseed[2] = (
unsigned short)accu;
213 return ldexp((
double)xseed[0], -48)
214 + ldexp((
double)xseed[1], -32)
215 + ldexp((
double)xseed[2], -16);
223 state48[0] = (
unsigned short)(seed & 0xffff);
224 state48[1] = (
unsigned short)(seed >> 16);
235 #elif STXXL_BOOST_RANDOM
238 return _erand48(state48);
244 template <
class UniformRGen_ = random_uniform_fast>
256 return static_cast<value_type>(uniform() * double(N));
272 return static_cast<value_type>(uniform() * (18446744073709551616.));
278 return static_cast<value_type>(uniform() * double(N));
283 #pragma warning(pop) // assignment operator could not be generated
288 #endif // !STXXL_COMMON_RAND_HEADER
random_number64(unsigned seed=0)
Uniform [0, N) pseudo-random generator.
void srandom_number32(unsigned seed=0)
Set a seed value for random_number32.
random_number(unsigned seed=0)
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
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_number8_r(unsigned seed=0)
#define STXXL_END_NAMESPACE
Slow and precise uniform [0, 2^64) pseudo-random generator.