Project

General

Profile

Task #279 » random3.c

Alexander Kamkin, 06/28/2010 11:26 AM

 
/*
Random number generator from http://www.concentric.net/~Ttwang/tech/rndtest.htm
Article "Random Number Based Test Case Generation"
Thomas Wang, November 2000
last update November 2000
*/
static int s1 = 0x52f7d319;
static int s2 = 0x6e28014a;

int nextInt(void)
{
// MWC generator, period length 1014595583
int v1 = s1;
int v2 = s2;
return ((s1 = 36969 * (v1 & 0xffff) + ((unsigned int)v1 >> 16)) << 16) ^ (s2 = 30963 * (v2 & 0xffff) + ((unsigned int)v2 >> 16));
}

long long nextLong(void)
{
return (((long long) nextInt()) << 32) + nextInt();
}

float nextFloat(void) /* from 0.0 to 0.99999999 */
{
return 5.9604645e-8f * (0x00ffffff & nextInt());
}

double nextDouble(void) /* from 0.0 to 0.99999999 */
{
return 2.22044604925031e-16 * (0x000fffffffffffffLL & nextLong());
}
(2-2/2)