RANDOMU Function
Returns one or more uniformly distributed floating-point pseudo-random numbers over the range 0 < Y < 1.0.
Usage
result = RANDOMU(seed[, dim1, ... , dimn])
Input Parameters
seed—A named variable containing the seed value for random number generation. seed is updated by RANDOMU once for each random number generated. The initial value of seed should be set to different values in order to obtain different random sequences. If seed is undefined, it is derived from the current system time.
dimi—(optional) The dimensions of the result. May be any scalar expression. Up to eight dimensions may be specified.
Returned Value
result—Returns a scalar or array of pseudo-random numbers over the range 0 < Y < 1.0. If no dimensions are specified, RANDOMU returns a scalar result.
Keywords
None.
Discussion
Uniform distribution means that, given a large enough sample of randomly-generated numbers, the same quantity of each number will be produced by RANDOMU. In other words, if you were to select a number generated by RANDOMU, you are as likely to pick any one number as another.
Example
This example simulates the result of rolling two dice 10,000 times, and plots the distribution of the total using RANDOMU:
PLOT, HISTOGRAM(FIX(6 * RANDOMU(s, 10000)) + $
FIX(6 * RANDOMU(s, 10000)) + 2)
In the above statement, the expression RANDOMU(S, 10000) is a 10,000-element floating-point array of random numbers greater or equal to 0 and less than 1. Multiplying this by 6 converts the range to 0 < Y < 6.
Applying the FIX function yields 10,000-point integer vectors from 0 to 5, one less than the numbers on one die. This is done twice, once for each die, and then 2 is added to obtain a vector from 2 to 12, the total of two die.
The HISTOGRAM function makes a vector in which each element contains the number of occurrences of dice rolls whose total is equal to the subscript of the element.
This vector is plotted by the PLOT procedure.
See Also
Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.