18 #ifndef INCLUDED_IMATHRANDOM_H
19 #define INCLUDED_IMATHRANDOM_H
27 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
56 unsigned long int _state;
84 unsigned short int _state[3];
89 template <
class Vec,
class Rand>
94 template <
class Vec,
class Rand>
104 template <
class Vec,
class Rand>
126 _state = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
137 _state = 1664525L * _state + 1013904223L;
145 return !!(_state & 2147483648UL);
152 return _state & 0xffffffff;
159 return rangeMin * (1 -
f) + rangeMax * f;
165 seed = (seed * 0xa5a573a5L) ^ 0x5a5a5a5aL;
167 _state[0] = (
unsigned short int) (seed & 0xFFFF);
168 _state[1] = (
unsigned short int) ((seed >> 16) & 0xFFFF);
169 _state[2] = (
unsigned short int) (seed & 0xFFFF);
180 return nrand48 (_state) & 1;
186 return nrand48 (_state);
192 return erand48 (_state);
199 return rangeMin * (1 -
f) + rangeMax * f;
202 template <
class Vec,
class Rand>
210 for (
unsigned int i = 0; i < Vec::dimensions (); i++)
211 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
212 }
while (v.length2 () > 1);
217 template <
class Vec,
class Rand>
222 typename Vec::BaseType
length;
226 for (
unsigned int i = 0; i < Vec::dimensions (); i++)
227 v[i] = (
typename Vec::BaseType) rand.nextf (-1, 1);
229 length = v.length ();
230 }
while (length > 1 || length == 0);
235 template <
class Rand>
245 x =
float (rand.nextf (-1, 1));
246 y =
float (rand.nextf (-1, 1));
247 length2 = x * x + y *
y;
248 }
while (length2 >= 1 || length2 == 0);
250 return x *
sqrt (-2 *
log (
double (length2)) / length2);
253 template <
class Vec,
class Rand>
257 return hollowSphereRand<Vec> (rand) *
gaussRand (rand);
260 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
262 #endif // INCLUDED_IMATHRANDOM_H
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
IMATH_HOSTDEVICE Vec gaussSphereRand(Rand &rand)
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_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 IMATH_EXPORT float nextf()
Get the next value in the sequence (range: [0 ... 1[)
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
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.