I am using the math.random function in my game to implement a random decision.
1 2 3 | local numHowManyBalls = allBallsGroup.numChildren local numRandomIndex = math.random(1, numHowManyBalls) |
math.randomseed(N)
sets N as the seed for the pseudo random number generator.
behind the scenes all "random" number generators use a seed
math.randomseed(5)
will always return the same sequence of numbers, while
math.randomseed(os.time())
different sequences, since os.time()
is a unique number
Thanks tetu
I am guessing I definitely need to use randomseed
Would I be fine just adding the following near the beginning of my main.lua file and this would take care of all the different scenarios where I generate random numbers in my game?
1 | math.randomseed(os.time()) |
yes, put the random seed call near the beginning of main.lua
:-)
views:1394 update:2011/10/6 9:28:12