lua-users home
lua-l archive

Re: Why is the first random number after randomseed() not random?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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;
}

AltStyle によって変換されたページ (->オリジナル) /