good seeding for math.random

General discussion about LÖVE, Lua, game development, puns, and unicorns.
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: good seeding for math.random

Post by osuf oboys »

It's not weird because changing the seed by 1 changes the first random number only by a little as well. The ranom number is 32 bits or the like and is scaled to the given range (although modulus would have been better) and hence a change in a minute results in no change in the random number 1 to 9. Call math.random once and you should be fine.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
User avatar
Simtex
Prole
Posts: 39
Joined: Sun Dec 14, 2008 5:31 am

Re: good seeding for math.random

Post by Simtex »

Some of you are probably familiar with Brain Damage, another Lua based game engine. One of the changes the author made to default Lua behavior was the random number generation, here's what he listed as his reasons:
math.randomseed was provided by Lua, but was overwritten by Brain Damage. The reason I chose to rewrite math.randomseed was to provide a mechanism for seeding the RNG based on the system time in milliseconds, and to use a better RNG algorithm. Currently, Brain Damage uses the SIMD oriented Fast Mersenne Twister (SFMT) pseudo-random number generator.
It might be worthwhile for LÖVE to snag that from Brain Damage (I believe the licenses are compatible).
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests