|
|||||
|
||||||
Related Topics | Other Library Functions |
function |
random.uniform |
Library: Random number utilities (OMRANDOM)
Import: omrandom.xmd |
Return type: Integer Returns: A pseudo-random number |
define external integer function random.uniform from value integer low optional to value integer high optional
Argument definitions
This function returns a pseudo-random number in the given range. If the lower bound is not given, 0 is used. If the higher bound is not given, then random.max-random is used.
This program outputs 10 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
This program outputs 5 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 "prime" 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 the upper and lower bounds should not exceed random.max-random (32767). If it does, not all discrete values in the range may be returned.
Related Topics |
Other Library Functions
|
Copyright © Stilo International plc, 1988-2010.