Unbias a random generator: Difference between revisions

Content added Content deleted
(Simpler D code)
(→‎{{header|C}}: bug fix)
Line 95: Line 95:
int r, rand_max = RAND_MAX - (RAND_MAX % bias);
int r, rand_max = RAND_MAX - (RAND_MAX % bias);
while ((r = rand()) > rand_max);
while ((r = rand()) > rand_max);
return rand() < rand_max / bias;
return r < rand_max / bias;
}
}