Generate random floating-point numbers
This functionality does not run in MATLAB.
frandom() returns a pseudo-random floating point number from the interval .
frandom(seed) returns a generator of pseudo-random floating-point numbers from the interval .
The calls frandom() produce uniformly distributed floating-point numbers from the interval .
r := frandom(seed) produces a random number generator r. Subsequent calls r() return uniformly distributed floating-point numbers from the interval .
Generators created with CurrentTime use the time (in milliseconds) at their creation as their seed values. Generators created shortly after one another may thus return the same numbers.
Generators created in separate calls to frandom do not influence one another.
Each time MuPAD® is started or re-initialized with the reset function, random generators not using CurrentTime produce the same sequence of numbers.
frandom is the recommended function for generating uniform random floating-point numbers. It is much faster than the function random which produces uniform integer numbers.
The function stats::uniformRandom allows to produce uniformly distributed floating-point numbers on arbitrary finite intervals. The stats library also provides random generators with various other distributions.
frandom and the procedures returned by frandom are sensitive to the environment variable DIGITS which determines the numerical working precision.
frandom changes its internal state when generating a number and will thus produce a different number on the next call.
The following call produces a sequence of pseudo-random numbers. Note that an index variable i must be used in the construction of the sequence. A call such as frandom() $8 would produce 8 copies of the same random value:
frandom() $ i = 1..8
frandom reacts to DIGITS, producing numbers which are equally random in the later digits as in the beginning ones:
DIGITS := 200: frandom(), frandom()
frandom(seed), for some integer value of seed, returns a generator of floating-point numbers. For different generators created with the same seed, the sequences of numbers will be identical (apart from the digits cut off when producing numbers at lower settings of DIGITS):
r1 := frandom(42): r2 := frandom(42): r3 := frandom(42): r1() $ i=1..4; r2() $ i=1..4; DIGITS := 20: r3() $ i=1..4;
delete r1, r2, r3, DIGITS:
Usually, frandom is used to generate experimental input or "random" examples. In these cases, reproducibility is a good thing. However, on occasion a "more random" sequence is desirable. The usual way to get a random seed in a program is to use the current system time, which can be done by using CurrentTime as the value of seed:
r := frandom(CurrentTime):
r(), r(), r(), r()
frandom uses a linear congruence generator to directly manipulate the internal representation of a DOM_FLOAT.