[Change] Instead of seeding the MT with a bit of random, we use full urandom.
This commit is contained in:
parent
ceb96b0f13
commit
1391fabc65
14
src/rng.c
14
src/rng.c
@ -24,13 +24,16 @@ static uint32_t mt_getInt(void);
|
||||
|
||||
void rng_init(void) {
|
||||
uint32_t i;
|
||||
int need_init;
|
||||
|
||||
need_init = 1; // Initialize by default.
|
||||
#ifdef LINUX
|
||||
int fd; char buf[4];
|
||||
fd = open("/dev/random", O_RDONLY);
|
||||
int fd;
|
||||
fd = open("/dev/urandom", O_RDONLY); // /dev/urandom is better then time seed.
|
||||
if(fd != -1) {
|
||||
if(read(fd, buf, 4) < 4)
|
||||
memcpy(&i, buf, 4);
|
||||
i = sizeof(uint32_t)*624;
|
||||
if(read(fd, &MT, i) == 1)
|
||||
need_init = 0;
|
||||
else
|
||||
i = rng_timeEntropy();
|
||||
close(fd);
|
||||
@ -39,7 +42,8 @@ void rng_init(void) {
|
||||
#else
|
||||
i = rng_timeEntropy();
|
||||
#endif
|
||||
mt_initArray(i);
|
||||
if(need_init)
|
||||
mt_initArray(i);
|
||||
for(i = 0; i < 10; i++)
|
||||
// Generate numbers to get away from poor initial values.
|
||||
mt_genArray();
|
||||
|
Loading…
Reference in New Issue
Block a user