It may not be random enough for you though
Code: Select all
class CRandSequence
{
public:
u32 A, B;
CRandSequence::CRandSequence(u32 seeda, u32 seedb)
{
Set(seeda,seedb);
}
void CRandSequence::Set(u32 seeda, u32 seedb, u32 loops=0)
{
A = seeda+((u32)-1)/2;
B = seedb+((u32)-1)/2;
for (s32 n=0; n<loops; ++n) getInt();
}
// returns the next number in the sequence as a u32
u32 CRandSequence::getInt()
{
u32 ret = A + B;
A=B; B=ret;
return ret;
}
// returns the next number in the sequence as a float 0.0 to 1.0
f32 CRandSequence::getFloat()
{
u32 ret = A + B;
A=B; B=ret;
return (f32) ( (f64)ret/(f64)((u32)-1) );
}
};