function
Library: Random number utilities (OMRANDOM)
Import : omrandom.xmd |
Returns: A pseudo-random number |
export external integer function uniform from value integer low optional to value integer high optional
Argument definitions
random.uniform
returns a pseudo-random number in the given range. If low is not given, it defaults
to 0
. If high is not given, then random.max-random
is used.
The following program outputs ten random numbers between 0
and random.max-random
(32767
), inclusive:
import "omutil.xmd" prefixed by util. import "omrandom.xmd" prefixed by random. process random.set-seed to util.millisecond-time repeat to 10 output "d" % random.uniform || "%n" again
The following program outputs five random numbers between 1
and 6
, inclusive:
import "omutil.xmd" prefixed by util. import "omrandom.xmd" prefixed by random. process random.set-seed to util.millisecond-time repeat to 5 output "d" % random.uniform from 1 to 6 || " " again output "%n"
In the examples above, random.set-seed
uses the millisecond timer value to initialize the random
number generator. This ensures a different sequence of pseudo-random numbers each time the program is run.
The distribution of returned values over the range is uniform. (Each value has the same chance of occurring.)
The difference between high and low should not exceed random.max-random
(32767
). If it does, not all discrete values in the range may be returned.