[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Am I misunderstanding random numbers?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 16 Mar 2010 16:49:25 -0300
> When I run the following snippet, I get unexpected results. About
> 50% of the results are the same (I've omitted the different ones
> from my results list, because they're not as interesting :-)
>
>
> math.randomseed( __randomSeed )
> print ("Seed: ".. __randomSeed, math.random(10000),math.random(10000),math.random(10000),math.random(10000))
>
> =====
>
> Seed: 3063121584 12 2356 6482 744
> Seed: 2428144928 12 2356 6482 744
> Seed: 3559301251 12 2356 6482 744
> Seed: 4287790062 12 2356 6482 744
> Seed: 2737803158 12 2356 6482 744
> Seed: 2458923424 12 2356 6482 744
I think all these seeds are larger than INTMAX, so they are being
truncated to 0x80000000 (or something similar).
This is probably a bug in Lua, since srand should accept unsigned
ints.
-- Roberto