36 #ifndef INCLUDED_IMATHRANDOM_H 37 #define INCLUDED_IMATHRANDOM_H 78 Rand32 (
unsigned long int seed = 0);
85 void init (
unsigned long int seed);
99 unsigned long int nexti ();
113 float nextf (
float rangeMin,
float rangeMax);
120 unsigned long int _state;
138 Rand48 (
unsigned long int seed = 0);
145 void init (
unsigned long int seed);
173 double nextf (
double rangeMin,
double rangeMax);
178 unsigned short int _state[3];
187 template <
class Vec,
class Rand>
197 template <
class Vec,
class Rand>
207 template <
class Rand>
218 template <
class Vec,
class Rand>
227 double erand48 (
unsigned short state[3]);
229 long int nrand48 (
unsigned short state[3]);
242 _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
256 _state = 1664525L * _state + 1013904223L;
265 return !!(_state & 2147483648UL);
269 inline unsigned long int 273 return _state & 0xffffffff;
281 return rangeMin * (1 - f) + rangeMax * f;
288 seed = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
290 _state[0] = (
unsigned short int) (seed & 0xFFFF);
291 _state[1] = (
unsigned short int) ((seed >> 16) & 0xFFFF);
292 _state[2] = (
unsigned short int) (seed & 0xFFFF);
328 return rangeMin * (1 - f) + rangeMax * f;
332 template <
class Vec,
class Rand>
340 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
341 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
343 while (v.length2() > 1);
349 template <
class Vec,
class Rand>
354 typename Vec::BaseType length;
358 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
359 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
363 while (length > 1 || length == 0);
369 template <
class Rand>
379 x = float (rand.nextf (-1, 1));
380 y = float (rand.nextf (-1, 1));
381 length2 = x * x + y * y;
383 while (length2 >= 1 || length2 == 0);
385 return x * sqrt (-2 * log (
double (length2)) / length2);
389 template <
class Vec,
class Rand>
393 return hollowSphereRand <Vec> (rand) *
gaussRand (rand);
bool nextb()
Definition: ImathRandom.h:261
long int lrand48()
Definition: ImathRandom.cpp:156
Definition: ImathRandom.h:70
Vec hollowSphereRand(Rand &rand)
Definition: ImathRandom.h:351
Vec gaussSphereRand(Rand &rand)
Definition: ImathRandom.h:391
float nextf()
Definition: ImathRandom.cpp:172
void srand48(long int seed)
Definition: ImathRandom.cpp:163
double erand48(unsigned short state[3])
Definition: ImathRandom.cpp:103
double nextf()
Definition: ImathRandom.h:318
Vec solidSphereRand(Rand &rand)
Definition: ImathRandom.h:334
unsigned long int nexti()
Definition: ImathRandom.h:270
Definition: ImathRandom.h:130
float gaussRand(Rand &rand)
Definition: ImathRandom.h:371
long int nexti()
Definition: ImathRandom.h:311
void init(unsigned long int seed)
Definition: ImathRandom.h:286
Rand32(unsigned long int seed=0)
Definition: ImathRandom.h:247
Rand48(unsigned long int seed=0)
Definition: ImathRandom.h:297
bool nextb()
Definition: ImathRandom.h:304
long int nrand48(unsigned short state[3])
Definition: ImathRandom.cpp:142
Definition: ImathBox.h:67
double drand48()
Definition: ImathRandom.cpp:135
void init(unsigned long int seed)
Definition: ImathRandom.h:240