Once again, take srand()/random() out of the initialization chain.
They have exactly the wrong kind of randomness for this job - not returning consistent sequences across different platforms or C library versions, and because pseodorandom not really better than sampling the clock.
This commit is contained in:
parent
54afefba94
commit
2fdd509f32
3 changed files with 6 additions and 7 deletions
2
main.c
2
main.c
|
@ -99,7 +99,7 @@ int main(int argc, char *argv[]) {
|
||||||
lcgstate.a = 1093;
|
lcgstate.a = 1093;
|
||||||
lcgstate.c = 221587;
|
lcgstate.c = 221587;
|
||||||
lcgstate.m = 1048576;
|
lcgstate.m = 1048576;
|
||||||
set_seed_from_time();
|
set_seed((long)time(NULL));
|
||||||
|
|
||||||
/* Read the database if we have not yet done so */
|
/* Read the database if we have not yet done so */
|
||||||
|
|
||||||
|
|
9
misc.c
9
misc.c
|
@ -722,7 +722,8 @@ L2: ATDWRF=I;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Utility routines (SETBIT, TSTBIT, set_seed_from_time, get_next_lcg_value, randrange, RNDVOC, BUG) */
|
/* Utility routines (SETBIT, TSTBIT, set_seed, get_next_lcg_value,
|
||||||
|
* randrange, RNDVOC, BUG) */
|
||||||
|
|
||||||
#undef SETBIT
|
#undef SETBIT
|
||||||
long fSETBIT(long BIT) {
|
long fSETBIT(long BIT) {
|
||||||
|
@ -758,11 +759,9 @@ long TSTBIT;
|
||||||
#define TSTBIT(MASK,BIT) fTSTBIT(MASK,BIT)
|
#define TSTBIT(MASK,BIT) fTSTBIT(MASK,BIT)
|
||||||
#undef RNDVOC
|
#undef RNDVOC
|
||||||
|
|
||||||
void set_seed_from_time(void)
|
void set_seed(long seedval)
|
||||||
{
|
{
|
||||||
/* Use the current system time to get seed the ISO rand() function, from which we get a seed for the LCG. */
|
lcgstate.x = (unsigned long) seedval % lcgstate.m;
|
||||||
srand(time(NULL));
|
|
||||||
lcgstate.x = (unsigned long) rand() % lcgstate.m;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long get_next_lcg_value(void)
|
unsigned long get_next_lcg_value(void)
|
||||||
|
|
2
misc.h
2
misc.h
|
@ -72,6 +72,6 @@ extern long fIABS(long);
|
||||||
#define IABS(N) fIABS(N)
|
#define IABS(N) fIABS(N)
|
||||||
extern long fMOD(long,long);
|
extern long fMOD(long,long);
|
||||||
#define MOD(N,M) fMOD(N,M)
|
#define MOD(N,M) fMOD(N,M)
|
||||||
extern void set_seed_from_time(void);
|
extern void set_seed(long);
|
||||||
extern unsigned long get_next_lcg_value(void);
|
extern unsigned long get_next_lcg_value(void);
|
||||||
extern long randrange(long);
|
extern long randrange(long);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue