18 #ifndef INCLUDED_ATOMSMATHRANDOM_H
19 #define INCLUDED_ATOMSMATHRANDOM_H
21 #include <AtomsMath/ImathExport.h>
22 #include <AtomsMath/ImathNamespace.h>
27 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_ENTER
37 ATOMSMATH_HOSTDEVICE
Rand32 (
unsigned long int seed = 0);
40 ATOMSMATH_HOSTDEVICE
void init (
unsigned long int seed);
43 ATOMSMATH_HOSTDEVICE
bool nextb();
46 ATOMSMATH_HOSTDEVICE
unsigned long int nexti();
49 ATOMSMATH_HOSTDEVICE
float nextf();
52 ATOMSMATH_HOSTDEVICE
float nextf (
float rangeMin,
float rangeMax);
55 ATOMSMATH_HOSTDEVICE
void next();
57 unsigned long int _state;
68 ATOMSMATH_HOSTDEVICE
Rand48 (
unsigned long int seed = 0);
71 ATOMSMATH_HOSTDEVICE
void init (
unsigned long int seed);
74 ATOMSMATH_HOSTDEVICE
bool nextb();
77 ATOMSMATH_HOSTDEVICE
long int nexti();
80 ATOMSMATH_HOSTDEVICE
double nextf();
83 ATOMSMATH_HOSTDEVICE
double nextf (
double rangeMin,
double rangeMax);
86 unsigned short int _state[3];
91 template <
class Vec,
class Rand> ATOMSMATH_HOSTDEVICE Vec solidSphereRand (Rand& rand);
95 template <
class Vec,
class Rand> ATOMSMATH_HOSTDEVICE Vec hollowSphereRand (Rand& rand);
99 template <
class Rand> ATOMSMATH_HOSTDEVICE
float gaussRand (Rand& rand);
104 template <
class Vec,
class Rand> ATOMSMATH_HOSTDEVICE Vec gaussSphereRand (Rand& rand);
112 ATOMSMATH_HOSTDEVICE ATOMSMATH_EXPORT
double erand48 (
unsigned short state[3]);
113 ATOMSMATH_HOSTDEVICE ATOMSMATH_EXPORT
double drand48();
114 ATOMSMATH_HOSTDEVICE ATOMSMATH_EXPORT
long int nrand48 (
unsigned short state[3]);
115 ATOMSMATH_HOSTDEVICE ATOMSMATH_EXPORT
long int lrand48();
116 ATOMSMATH_HOSTDEVICE ATOMSMATH_EXPORT
void srand48 (
long int seed);
127 _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
138 _state = 1664525L * _state + 1013904223L;
146 return !!(_state & 2147483648UL);
149 inline unsigned long int
153 return _state & 0xffffffff;
160 return rangeMin * (1 - f) + rangeMax * f;
166 seed = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
168 _state[0] = (
unsigned short int) (seed & 0xFFFF);
169 _state[1] = (
unsigned short int) ((seed >> 16) & 0xFFFF);
170 _state[2] = (
unsigned short int) (seed & 0xFFFF);
181 return nrand48 (_state) & 1;
187 return nrand48 (_state);
193 return erand48 (_state);
200 return rangeMin * (1 - f) + rangeMax * f;
203 template <
class Vec,
class Rand>
205 solidSphereRand (Rand& rand)
211 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
212 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
213 }
while (v.length2() > 1);
218 template <
class Vec,
class Rand>
220 hollowSphereRand (Rand& rand)
223 typename Vec::BaseType length;
227 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
228 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
231 }
while (length > 1 || length == 0);
236 template <
class Rand>
238 gaussRand (Rand& rand)
246 x = float (rand.nextf (-1, 1));
247 y = float (rand.nextf (-1, 1));
248 length2 = x * x + y * y;
249 }
while (length2 >= 1 || length2 == 0);
251 return x * sqrt (-2 * log (
double (length2)) / length2);
254 template <
class Vec,
class Rand>
256 gaussSphereRand (Rand& rand)
258 return hollowSphereRand<Vec> (rand) * gaussRand (rand);
261 ATOMSMATH_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImathRandom.h:33
ATOMSMATH_HOSTDEVICE unsigned long int nexti()
Get the next value in the sequence (range: [0 ... 0xffffffff])
Definition: ImathRandom.h:150
ATOMSMATH_HOSTDEVICE bool nextb()
Get the next value in the sequence (range: [false, true])
Definition: ImathRandom.h:142
ATOMSMATH_HOSTDEVICE Rand32(unsigned long int seed=0)
Constructor, given a seed.
Definition: ImathRandom.h:130
ATOMSMATH_HOSTDEVICE float nextf()
Get the next value in the sequence (range: [0 ... 1[)
ATOMSMATH_HOSTDEVICE void init(unsigned long int seed)
Re-initialize with a given seed.
Definition: ImathRandom.h:125
Definition: ImathRandom.h:64
ATOMSMATH_HOSTDEVICE long int nexti()
Get the next value in the sequence (range: [0 ... 0x7fffffff])
Definition: ImathRandom.h:185
ATOMSMATH_HOSTDEVICE void init(unsigned long int seed)
Re-initialize with a given seed.
Definition: ImathRandom.h:164
ATOMSMATH_HOSTDEVICE double nextf()
Get the next value in the sequence (range: [0 ... 1[)
Definition: ImathRandom.h:191
ATOMSMATH_HOSTDEVICE Rand48(unsigned long int seed=0)
Constructor.
Definition: ImathRandom.h:173
ATOMSMATH_HOSTDEVICE bool nextb()
Get the next value in the sequence (range: [false, true])
Definition: ImathRandom.h:179