| Support Forum Library Source SourceForge Page G3D Web Page |
Fast random numbers using a precomputed data table. More...
Inherits G3D::Random.
Classes | |
| class | HemiUniformData |
| Put the cosHemi and the uniform together so that when alternating between them we stay in cache. More... | |
| class | SphereBitsData |
Public Member Functions | |
| PrecomputedRandom (const HemiUniformData *data1, const SphereBitsData *data2, int dataSize, uint32 seed=0xF018A4D2) | |
| PrecomputedRandom (int dataSize, uint32 seed=0xF018A4D2) | |
| ~PrecomputedRandom () | |
| virtual uint32 | bits () |
| Each bit is random. | |
| virtual void | cosHemi (float &x, float &y, float &z) |
| Returns 3D unit vectors distributed according to a cosine distribution about the z axis. | |
| virtual void | cosPowHemi (const float k, float &x, float &y, float &z) |
Returns 3D unit vectors distributed according to a cosine power distribution ( ) about the z-axis. | |
| virtual void | cosSphere (float &x, float &y, float &z) |
| Returns 3D unit vectors distributed according to a cosine distribution about the z-axis. | |
| virtual float | gaussian (float mean, float stdev) |
| Normally distributed reals. | |
| virtual void | hemi (float &x, float &y, float &z) |
| Returns 3D unit vectors uniformly distributed on the hemisphere about the z-axis. | |
| virtual int | integer (int min, int max) |
| Uniform random integer on the range [min, max]. | |
| virtual void | reset (uint32 seed=0xF018A4D2, bool threadsafe=true) |
| virtual void | sphere (float &x, float &y, float &z) |
| Returns 3D unit vectors uniformly distributed on the sphere. | |
| virtual float | uniform (float low, float high) |
| Uniform random float on the range [min, max]. | |
| virtual float | uniform () |
| Uniform random float on the range [0, 1]. | |
Static Public Member Functions | |
| static Random & | common () |
| A shared instance for when the performance and features but not consistency of the class are desired. | |
Protected Types | |
| enum | { N = 624, M = 397, R = 31, U = 11, S = 7, T = 15, L = 18, A = 0x9908B0DF, B = 0x9D2C5680, C = 0xEFC60000 } |
| Constants (important for the algorithm; do not modify) More... | |
Protected Member Functions | |
| virtual void | generate () |
| Generate the next N ints, and store them for readback later. | |
Protected Attributes | |
| int | index |
| Index into state. | |
| Spinlock | lock |
| Prevents multiple overlapping calls to generate(). | |
| bool | m_freeData |
| If true, free m_hemiUniform and m_sphereBits in destructor. | |
| const HemiUniformData * | m_hemiUniform |
| Array of 2^n elements. | |
| int | m_index |
| int | m_modMask |
| 2^n - 1; the AND mask for computing a fast modulo | |
| const SphereBitsData * | m_sphereBits |
| bool | m_threadsafe |
| uint32 * | state |
| State vector (these are the next N values that will be returned) | |
Fast random numbers using a precomputed data table.
e.g., generates cosHemi about 13x faster than Random. This is useful for quickly generating seeded random numbers for reproducibility. G3D::Random takes a long time to seed; this is instantaneous (providing the precomputed data is already available.)
Not threadsafe.
|
protectedinherited |
| G3D::PrecomputedRandom::PrecomputedRandom | ( | const HemiUniformData * | data1, |
| const SphereBitsData * | data2, | ||
| int | dataSize, | ||
| uint32 | seed = 0xF018A4D2 |
||
| ) |
| dataSize | Number of random numbers that can be requested before periodicity. Must be a power of 2. |
| G3D::PrecomputedRandom::~PrecomputedRandom | ( | ) |
|
virtual |
Each bit is random.
Subclasses can choose to override just this method and the other methods will all work automatically.
Reimplemented from G3D::Random.
|
staticinherited |
A shared instance for when the performance and features but not consistency of the class are desired.
It is slightly (10%) faster to use a distinct instance than to use the common one.
Threadsafe.
|
virtual |
Returns 3D unit vectors distributed according to a cosine distribution about the z axis.
Reimplemented from G3D::Random.
|
virtual |
Returns 3D unit vectors distributed according to a cosine power distribution (
) about the z-axis.
Reimplemented from G3D::Random.
|
virtualinherited |
Returns 3D unit vectors distributed according to a cosine distribution about the z-axis.
|
virtualinherited |
Normally distributed reals.
|
protectedvirtualinherited |
Generate the next N ints, and store them for readback later.
Called from bits()
|
virtualinherited |
Returns 3D unit vectors uniformly distributed on the hemisphere about the z-axis.
Uniform random integer on the range [min, max].
|
virtualinherited |
|
virtual |
Returns 3D unit vectors uniformly distributed on the sphere.
Reimplemented from G3D::Random.
|
virtual |
Uniform random float on the range [min, max].
Reimplemented from G3D::Random.
|
virtual |
Uniform random float on the range [0, 1].
Reimplemented from G3D::Random.
|
protectedinherited |
Index into state.
|
protectedinherited |
Prevents multiple overlapping calls to generate().
|
protected |
If true, free m_hemiUniform and m_sphereBits in destructor.
|
protected |
Array of 2^n elements.
|
protected |
|
protected |
2^n - 1; the AND mask for computing a fast modulo
|
protected |
|
protectedinherited |
|
protectedinherited |
State vector (these are the next N values that will be returned)
1.8.2