18 #ifndef INCLUDED_IMATHRANDOM_H
19 #define INCLUDED_IMATHRANDOM_H
27 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
57 unsigned long int _state;
86 unsigned short int _state[3];
125 _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
136 _state = 1664525L * _state + 1013904223L;
144 return !!(_state & 2147483648UL);
151 return _state & 0xffffffff;
158 return rangeMin * (1 -
f) + rangeMax * f;
164 seed = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
166 _state[0] = (
unsigned short int) (seed & 0xFFFF);
167 _state[1] = (
unsigned short int) ((seed >> 16) & 0xFFFF);
168 _state[2] = (
unsigned short int) (seed & 0xFFFF);
179 return nrand48 (_state) & 1;
185 return nrand48 (_state);
191 return erand48 (_state);
198 return rangeMin * (1 -
f) + rangeMax * f;
201 template <
class Vec,
class Rand>
209 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
210 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
211 }
while (v.length2() > 1);
216 template <
class Vec,
class Rand>
221 typename Vec::BaseType
length;
225 for (
unsigned int i = 0; i < Vec::dimensions(); i++)
226 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
229 }
while (length > 1 || length == 0);
234 template <
class Rand>
244 x =
float (rand.nextf (-1, 1));
245 y =
float (rand.nextf (-1, 1));
246 length2 = x * x + y *
y;
247 }
while (length2 >= 1 || length2 == 0);
249 return x *
sqrt (-2 *
log (
double (length2)) / length2);
252 template <
class Vec,
class Rand>
256 return hollowSphereRand<Vec> (rand) *
gaussRand (rand);
259 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
261 #endif // INCLUDED_IMATHRANDOM_H
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
IMATH_HOSTDEVICE Vec gaussSphereRand(Rand &rand)
IMATH_HOSTDEVICE float nextf()
Get the next value in the sequence (range: [0 ... 1[)
vfloat4 sqrt(const vfloat4 &a)
GLuint GLsizei GLsizei * length
IMATH_HOSTDEVICE void init(unsigned long int seed)
Re-initialize with a given seed.
IMATH_HOSTDEVICE long int nexti()
Get the next value in the sequence (range: [0 ... 0x7fffffff])
IMATH_NAMESPACE::V2f float
IMATH_HOSTDEVICE unsigned long int nexti()
Get the next value in the sequence (range: [0 ... 0xffffffff])
IMATH_HOSTDEVICE float gaussRand(Rand &rand)
IMATH_HOSTDEVICE Rand32(unsigned long int seed=0)
Constructor, given a seed.
IMATH_HOSTDEVICE bool nextb()
Get the next value in the sequence (range: [false, true])
IMATH_HOSTDEVICE bool nextb()
Get the next value in the sequence (range: [false, true])
IMATH_HOSTDEVICE void init(unsigned long int seed)
Re-initialize with a given seed.
IMATH_HOSTDEVICE Vec hollowSphereRand(Rand &rand)
IMATH_HOSTDEVICE Vec solidSphereRand(Rand &rand)
OIIO_FORCEINLINE T log(const T &v)
IMATH_HOSTDEVICE double nextf()
Get the next value in the sequence (range: [0 ... 1[)
IMATH_HOSTDEVICE Rand48(unsigned long int seed=0)
Constructor.