33 : mBase( 214u ), mHaveNextNextGaussian( false )
37 : mBase( seed ), mHaveNextNextGaussian( false )
41 void seed(
unsigned long seedValue );
64 if( v <= 0 )
return 0;
71 if( v == 0 )
return 0;
84 return mFloatGen(mBase);
90 return mFloatGen(mBase) *
v;
96 return mFloatGen(mBase) * ( b -
a ) + a;
112 float costheta =
nextFloat( -1.0f, 1.0f );
119 return Vec3f( x, y, z );
132 if( mHaveNextNextGaussian ) {
133 mHaveNextNextGaussian =
false;
134 return mNextNextGaussian;
142 s = v1 * v1 + v2 *
v2;
144 while( s >= 1.0
f || s == 0.0
f );
148 mNextNextGaussian = v2 *
m;
149 mHaveNextNextGaussian =
true;
160 static void randSeed(
unsigned long seedValue );
183 if( v <= 0 )
return 0;
184 else return sBase() %
v;
190 if( v == 0 )
return 0;
191 else return sBase() %
v;
203 return sFloatGen(sBase);
209 return sFloatGen(sBase) *
v;
215 return sFloatGen(sBase) * ( b -
a ) + a;
231 float costheta =
randFloat( -1.0f, 1.0f );
238 return Vec3f( x, y, z );
251 static bool sHaveNextNextGaussian =
false;
252 static float sNextNextGaussian;
254 if( sHaveNextNextGaussian ) {
255 sHaveNextNextGaussian =
false;
256 return sNextNextGaussian;
261 v1 = 2.0f * sFloatGen(sBase) - 1.0f;
262 v2 = 2.0f * sFloatGen(sBase) - 1.0f;
264 s = v1 * v1 + v2 *
v2;
266 while( s >= 1.0
f || s == 0.0
f );
270 sNextNextGaussian = v2 *
m;
271 sHaveNextNextGaussian =
true;
279 std::uniform_real_distribution<float> mFloatGen;
280 float mNextNextGaussian;
281 bool mHaveNextNextGaussian;
283 static std::mt19937 sBase;
284 static std::uniform_real_distribution<float> sFloatGen;
static T sqrt(T x)
Definition: CinderMath.h:63
float nextFloat(float a, float b)
returns a random float in the range [a,b)
Definition: Rand.h:94
float randFloat()
returns a random float in the range [0.0f,1.0f]
Definition: Rand.h:303
void randSeed(unsigned long seedValue)
Resets the static random generator to the specific seed seedValue.
Definition: Rand.h:288
GLenum GLint GLint y
Definition: GLee.h:987
Definition: CinderMath.h:40
static T cos(T x)
Definition: CinderMath.h:46
bool nextBool()
returns a random boolean value
Definition: Rand.h:44
uint32_t nextUint()
returns a random integer in the range [0,4294967296)
Definition: Rand.h:56
static uint32_t randUint(uint32_t v)
returns a random integer in the range [0,v)
Definition: Rand.h:188
static int32_t randInt(int32_t v)
returns a random integer in the range [0,v)
Definition: Rand.h:181
Vec2< float > Vec2f
Definition: Vector.h:1314
static T sin(T x)
Definition: CinderMath.h:47
static uint32_t randUint()
returns a random integer in the range [0,4294967296)
Definition: Rand.h:175
static void randomize()
Resets the static random generator to a random seed based on the clock.
Definition: Rand.cpp:38
int32_t nextInt(int32_t v)
returns a random integer in the range [0,v)
Definition: Rand.h:62
static float randFloat(float a, float b)
returns a random float in the range [a,b)
Definition: Rand.h:213
float posNegFloat(float a, float b)
returns a random float in the range [a,b] or the range [-b,-a)
Definition: Rand.h:100
GLfloat GLfloat v1
Definition: GLee.h:2445
uint32_t nextUint(uint32_t v)
returns a random integer in the range [0,v)
Definition: Rand.h:69
static float randFloat(float v)
returns a random float in the range [0.0f,v)
Definition: Rand.h:207
Vec3< float > Vec3f
Definition: Vector.h:1317
Rand(unsigned long seed)
Definition: Rand.h:36
int32_t randInt()
returns a random integer in the range [0,2147483647]
Definition: Rand.h:294
Rand()
Definition: Rand.h:32
static Vec3f randVec3f()
returns a random Vec3f that represents a point on the unit sphere
Definition: Rand.h:228
float randPosNegFloat(float a, float b)
returns a random float in the range [a,b] or the range [-b,-a]
Definition: Rand.h:312
static float randPosNegFloat(float a, float b)
returns a random float in the range [a,b) or the range [-b,-a)
Definition: Rand.h:219
GLfloat GLfloat GLfloat v2
Definition: GLee.h:2451
int32_t nextInt(int32_t a, int32_t b)
returns a random integer in the range [a,b)
Definition: Rand.h:76
GLenum GLint x
Definition: GLee.h:987
static float randFloat()
returns a random float in the range [0.0f,1.0f)
Definition: Rand.h:201
static float randGaussian()
returns a random float via Gaussian distribution; refactor later
Definition: Rand.h:249
float nextFloat(float v)
returns a random float in the range [0.0f,v)
Definition: Rand.h:88
const GLdouble * v
Definition: GLee.h:1384
Vec3f randVec3f()
returns a random Vec3f that represents a point on the unit sphere
Definition: Rand.h:315
static void randSeed(unsigned long seedValue)
Resets the static random generator to the specific seed seedValue.
Definition: Rand.cpp:49
static bool randBool()
returns a random boolean value
Definition: Rand.h:163
GLdouble GLdouble z
Definition: GLee.h:1911
GLboolean GLboolean GLboolean b
Definition: GLee.h:2964
float nextFloat()
returns a random float in the range [0.0f,1.0f)
Definition: Rand.h:82
Vec3f nextVec3f()
returns a random Vec3f that represents a point on the unit sphere
Definition: Rand.h:109
Vec2f nextVec2f()
returns a random Vec2f that represents a point on the unit circle
Definition: Rand.h:123
#define M_PI
Definition: CinderMath.h:121
GLboolean GLboolean GLboolean GLboolean a
Definition: GLee.h:2964
float randGaussian()
returns a random float via Gaussian distribution
Definition: Rand.h:321
static int32_t randInt(int32_t a, int32_t b)
returns a random integer in the range [a,b)
Definition: Rand.h:195
Vec2f randVec2f()
returns a random Vec2f that represents a point on the unit circle
Definition: Rand.h:318
static int32_t randInt()
returns a random integer in the range [-2147483648,2147483647]
Definition: Rand.h:169
const GLfloat * m
Definition: GLee.h:13493
static Vec2f randVec2f()
returns a random Vec2f that represents a point on the unit circle
Definition: Rand.h:242
GLdouble s
Definition: GLee.h:1378
GLclampf f
Definition: GLee.h:15307
void seed(unsigned long seedValue)
Re-seeds the random generator.
Definition: Rand.cpp:54
int32_t nextInt()
returns a random integer in the range [-2147483648,2147483647]
Definition: Rand.h:50
bool randBool()
returns a random boolean value
Definition: Rand.h:291
float nextGaussian()
returns a random float via Gaussian distribution
Definition: Rand.h:130