Random |
Miscellaneous | |
Aptilis 1 |
Random(Range)
Random returns a random number between 0 (included) and
the 'range' parameter (excluded).
The random generator is initialized with a nearly
random seed each time Aptilis is launched, but you can
force a reinitialization, (that is using the time as the seed
for new random numbers) by indicating a negative range.
The absolute value of the range is then used to generate
a new random number.
Random can be very useful in the implementation of games.
Warning: The Unix implementation of random might cause some bias
with large ranges.
Return Value:
An integer random number n, with 0 <= n < range.
Example:
for i=1 to 5 print(random(10), "\n") end forResult:
7.0000 2.0000 2.0000 5.0000 4.0000 |
Notes
Random generators usually use a 'seed' or a starting point number
to generate pseudo random numbers. The quality of the 'randomness'
might vary from platform to platform, depending on how it has
been implemented into the different Operating Systems.
No computer generated random numbers are absolutely random, and
the more you run a randomizing generator, the more you are likely
to entcounter a pattern, ie. a recurring suite of numbers.
By repeatedly resetting the generator, you may introduce a random
factor, for example the time it takes a user to answer a question
and that will lessen the risk of a pattern occuring.