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>
189 solidSphereRand (Rand &rand);
197 template <
class Vec,
class Rand>
199 hollowSphereRand (Rand &rand);
207 template <
class Rand>
209 gaussRand (Rand &rand);
218 template <
class Vec,
class Rand>
220 gaussSphereRand (Rand &rand);
227 double erand48 (
unsigned short state[3]);
229 long int nrand48 (
unsigned short state[3]);
231 void srand48 (
long int seed);
240 Rand32::init (
unsigned long int seed)
242 _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
247 Rand32::Rand32 (
unsigned long int seed)
256 _state = 1664525L * _state + 1013904223L;
265 return !!(_state & 2147483648UL);
269 inline unsigned long int 273 return _state & 0xffffffff;
278 Rand32::nextf (
float rangeMin,
float rangeMax)
281 return rangeMin * (1 - f) + rangeMax * f;
286 Rand48::init (
unsigned long int seed)
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);
297 Rand48::Rand48 (
unsigned long int seed)
306 return Imath::nrand48 (_state) & 1;
313 return Imath::nrand48 (_state);
320 return Imath::erand48 (_state);
325 Rand48::nextf (
double rangeMin,
double rangeMax)
328 return rangeMin * (1 - f) + rangeMax * f;
332 template <
class Vec,
class Rand>
334 solidSphereRand (Rand &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>
351 hollowSphereRand (Rand &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>
371 gaussRand (Rand &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>
391 gaussSphereRand (Rand &rand)
393 return hollowSphereRand <Vec> (rand) * gaussRand (rand);
Definition: ImathRandom.h:70
Definition: ImathRandom.h:130
Definition: ImathBox.h:67