[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why is the first random number after randomseed() not random?
- From: Jürgen Hötzel <juergen@...>
- Date: Tue, 20 Mar 2007 00:21:32 +0100
On Mon, Mar 19, 2007 at 08:09:59PM -0300, Luiz Henrique de Figueiredo wrote:
> Lua relies on rand from libc. It must not be too clever about what it does
> with the result of rand lest it breaks its randomness (which may be weak
> already). So I think the fix for Lua is to call rand() a couple of times
> whenever the seed changes.
srand() is used to start the seed. Successive rand() calls will update the
internal seed so the next call to rand() will result in the next random
number from a sequence. Multiple calls to srand() will destroy randomness
if the seed is related to the previous seed.