[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why is the first random number after randomseed() not random?
- From: Sam Roberts <sroberts@...>
- Date: Mon, 19 Mar 2007 13:06:55 -0700
On Mon, Mar 19, 2007 at 12:20:39PM -0600, Gavin Kistner wrote:
> The Lua Wiki Math Library Tutorial page[1] says:
> "But beware! The first random number you get is not really 'randomized'
> (at least in Windows 2K and OS X)."
>
> I observe this same behavior locally. The first number returned by
> math.random() after a call to math.randomseed() is always the same. (See
> output below.)
I can't reproduce on linux with gnu libc v 3.4.
Is this the behaviour of the C library, or is it how lua is using the C
library, what does this report on the troubled systems?
------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int seed = time(NULL);
int _, i;
for(_=1; _<=10; _++) {
seed = seed + 1;
printf("seed with %d\n", seed);
srand(seed);
for(i=1; i<=5; i++) {
printf(" %d\n", rand());
}
}
return 0;
}