Back out "drop first N values" method of removing monotonically increased
seed->first value correlation. It breaks rand_r()... Other possible methods like shuffling inside aray will breaks rand_r() too, because it assumes only one word state, i.e. nothing extra can be added after seed assignment in srand(). BTW, for old formulae seed->first value correlation is not so monotonically increased as with other Linear Congruential Generators of this type only becase arithmetic overflow happens. But overflow affects distribution and lower bits very badly, as many articles says, such type of overflow not improves PRNG. So, monotonically increased seed->first value correlation problem remains...
This commit is contained in:
parent
eadbecd88b
commit
54d6accf9d
@ -51,8 +51,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <stdio.h>
|
||||
#endif /* TEST */
|
||||
|
||||
#define NSHUFF 100 /* to drop part of seed -> 1st value correlation */
|
||||
|
||||
static int
|
||||
do_rand(unsigned long *ctx)
|
||||
{
|
||||
@ -98,7 +96,7 @@ rand_r(unsigned int *ctx)
|
||||
}
|
||||
|
||||
|
||||
static u_long next = 892053144; /* after srand(1), NSHUFF counted */
|
||||
static u_long next = 1;
|
||||
|
||||
int
|
||||
rand()
|
||||
@ -110,11 +108,7 @@ void
|
||||
srand(seed)
|
||||
u_int seed;
|
||||
{
|
||||
int i;
|
||||
|
||||
next = seed;
|
||||
for (i = 0; i < NSHUFF; i++)
|
||||
(void)rand();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user