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;
109 : m_rnd32(seed), m_pos(4)
119 return ((
uint8*)&m_value)[m_pos];
134 inline value_type operator () ()
const
136 return (
double(rnd32()) * (0.5 / 0x80000000));
141 #pragma warning(push)
142 #pragma warning(disable:4512) // assignment operator could not be generated
153 typedef std::default_random_engine gen_type;
154 mutable gen_type gen;
155 typedef std::uniform_real_distribution<> uni_type;
156 mutable uni_type uni;
159 : gen(seed), uni(0.0, 1.0)
161 #elif STXXL_BOOST_RANDOM
162 typedef boost::minstd_rand base_generator_type;
163 base_generator_type generator;
164 boost::uniform_real<> uni_dist;
165 mutable boost::variate_generator<base_generator_type&, boost::uniform_real<> > uni;
168 : uni(generator, uni_dist)
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);
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>
255 inline value_type operator () (value_type N)
const
272 inline value_type operator () ()
const
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
void srandom_number32(unsigned seed=get_next_seed())
Set a seed value for random_number32.
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)...
#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. ...
void set_seed(unsigned seed)
Change the current seed.
#define STXXL_END_NAMESPACE
Slow and precise uniform [0, 2^64) pseudo-random generator.