int seed;
unsigned int lo, hi;
float noise;
seed = 1;
while(1)
{
// white noise generator
lo = 16807 * (seed & 0xFFFF);
hi = 16807 * (seed >> 16);
lo += (hi & 0x7FFF) << 16;
lo += hi >> 15;
if ( lo > 0x7FFFFFFF ) lo -= 0x7FFFFFFF;
seed = lo;
noise = (1.0/2147483647.0) * seed - 0.5f; // noise range: [-0.5, 0.5], 2147483647 = 2^31-1.
} |