mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 23:21:56 +00:00
some applications rely on the low bits of rand() to be reasonably good quality prng, so now it fixed by using the top bits of a 64 bit LCG, this is simple, has small state and passes statistical tests. D.E. Knuth attributes the multiplier to C.E. Haynes in TAOCP Vol2 3.3.4
16 lines
183 B
C
16 lines
183 B
C
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
|
|
static uint64_t seed;
|
|
|
|
void srand(unsigned s)
|
|
{
|
|
seed = s-1;
|
|
}
|
|
|
|
int rand(void)
|
|
{
|
|
seed = 6364136223846793005ULL*seed + 1;
|
|
return seed>>33;
|
|
}
|