I found several problems that Corona SDK. They have not solved any. Now I found a new one:
Try to write this code:
A = math.random (5, 99)
Hello = display.newText (A, 326, 245, Nil, 35)
Hello: SetTextColor (255,255,255)
I must be doing something wrong because you should see a number between 5 and 99. But, when running the program on the device, always shows the number 5.
You must start the program, close it and restart it. He always repeats the same.
Should not show any other number? In the simulator it does, on the device, no.
Just notice: in whatever language you code and on whatever platform, you always must provide some number (called ‘seed’) for random number generator.
Generaly there is no such thing as real random number generator - software random numbers are always calculated! Some complex algorithms with proper statistics but it always boils down to calculation. If you do not provide seed then algorithm always start with default value so results of calculation are will be always the same. Also each next call of math.random() is basing on previous results.
In conclusion:
Without providing randomization seed by math.randomseed(someValue) you will alw ays get the same results for random() function. The sames goes for ‘someValue’ - it cannot be always the same - so os.time() is used because it’ll will always differ (because time is constantly growing and does not repeat)
Just notice: in whatever language you code and on whatever platform, you always must provide some number (called ‘seed’) for random number generator.
Generaly there is no such thing as real random number generator - software random numbers are always calculated! Some complex algorithms with proper statistics but it always boils down to calculation. If you do not provide seed then algorithm always start with default value so results of calculation are will be always the same. Also each next call of math.random() is basing on previous results.
In conclusion:
Without providing randomization seed by math.randomseed(someValue) you will alw ays get the same results for random() function. The sames goes for ‘someValue’ - it cannot be always the same - so os.time() is used because it’ll will always differ (because time is constantly growing and does not repeat)