delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/27/06:34:19

Message-ID: <351B8EDC.4383@pobox.oleane.com>
Date: Fri, 27 Mar 1998 12:34:52 +0100
From: Francois Charton <deef AT pobox DOT oleane DOT com>
Organization: CCMSA
MIME-Version: 1.0
To: Noam Rotem <nrotem AT johnbryce DOT co DOT il>
CC: djgpp AT delorie DOT com
Subject: Re: real random numbers
References: <199803261827 DOT TAA14769 AT acp3bf DOT physik DOT rwth-aachen DOT de> <351B900D DOT C369EE6 AT johnbryce DOT co DOT il>

Noam Rotem wrote:
> 
> Can we somehow use the value of IP register combined with the time element to
> set a better seed and  unpredictable  sequences of random numbers?
> 

I am not sure this would increase to the quality. In particular, it will 
go wrong if you call the same program twice in a row, the IP register 
will have the same value when the srand() function is called...

If srand(time()) does not work (as Hans-Bernhard, I think the risk is 
more with two users starting the program at the same time, for instance 
in the case of a multiplayer game, than with the program needing less 
than a second to run), two kinds of solutions seem possible:

1- you could seed rand() with a timer function having lower granularity 
than the second, either available on your OS, or predefined as a TSR, you 
will not remove the problem, but make it less likely.

2- for better security, you could have a seeding procedures which 
guarantees that successive runs of your program never have the same seed. 
For instance, the seed could be an environment variable, which would be 
incremented every time srand() is called. In such case, though, you will 
have to check whether two series seeded by correlated seeds, like 
seed_n+1 = seed_n + 1 are not correlated... as far as I know, little 
theory is available on this subject.

You could also resort on more elaborate schemes, like reading seeds from 
a precalculated file or array, generate by a RNG (seeded by time(), this 
array certainly will not be generated more than once per second).

Francois

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019