I am working on game using Corona SDK with Lua as Programming Language . While getting random number from table , I am confused to use which one of following ?
math.random()
math.randomseed()
Will any one elaborate the exact difference between them ? So I can use the best one in my case.
random , math. randomseed. math. random() generates pseudo-random numbers uniformly distributed.
Lua random is one of the mathematical concept and it's a library function that can be used for to generate the pseudo-random numbers and it can be called in different ways like the method called without arguments and it will be return with pseudo-random real type of numbers with some uniform distributions time ...
In this case, random is actually pseudo-random. Given a seed, it will generate numbers with an equal distribution. But with the same seed, it will generate the same number sequence every time. If you want it to change, you'll have to change your seed.
It's a function that creates random numbers from a seed. It's just math. random() but instead of giving it a range of values you give it a seed value. If you give it the same seed value it returns the same number.
math.random
gives you random numbers. You probably will call this many times in a program that needs random numbers.
math.randomseed
determines where to start the sequence of random numbers given by math.random
. You probably will call just once in a program that needs random numbers.
It seems to be a common misconception that you need to call math.randomseed
before each time you call math.random
. This is wrong and will defeat the randomness of math.random
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With