Last active
December 11, 2015 11:18
-
-
Save dpasca/4592681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//================================================================== | |
class RandPool | |
{ | |
DVec<U32> mVals; | |
size_t mIterIdx; | |
public: | |
RandPool( size_t size, U32 seed=0 ) | |
: mIterIdx(0) | |
{ | |
DUT::RandMT rand( seed ); | |
mVals.resize( size ); | |
for (size_t i=0; i < size; ++i) | |
mVals[i] = rand.randomMT(); | |
} | |
void IterStart( size_t idx ) | |
{ | |
mIterIdx = idx % mVals.size(); | |
} | |
U32 IterNext() | |
{ | |
U32 val = mVals[mIterIdx]; | |
mIterIdx += 1; | |
if ( mIterIdx >= mVals.size() ) | |
mIterIdx = 0; | |
return val; | |
} | |
float IterNextFloat() | |
{ | |
const U32 PRECISION_N1 = (1 << 16) - 1; | |
const float OO_PRECISION = 1.f / (float)PRECISION_N1; | |
return (float)(IterNext() & PRECISION_N1) * OO_PRECISION; | |
} | |
float IterNextRangef( float a, float b ) | |
{ | |
return a + (b - a) * IterNextFloat(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment