rand - Maple Help

# Online Help

###### All Products    Maple    MapleSim

rand

random number generator

 Calling Sequence rand(r)

Parameters

 r - (optional) numeric range or positive integer

Description

 • With no arguments, the call rand() returns a random integer sampled uniformly from the range $0$ to ${10}^{12}-1$.
 • If the parameter r is an integer range a..b, the call rand(a..b) returns a procedure which, when called, generates random integers in the range a..b.
 • If r is a numeric range a..b and one of $a$ or $b$ is not an integer, the call rand(a..b) returns a procedure which, when called, generates random floating-point numbers in the range a..b.
 • If r is a single integer, the call rand(r) is the abbreviated form of rand(0..r-1).
 • More than one random number generator may be used at the same time, because rand(a..b) returns a Maple procedure. However, since all random number generators use the same underlying random number sequence, calls to one random number generator will affect the random numbers returned from another.

Details

 • rand calls RandomTools[MersenneTwister][GenerateInteger] or RandomTools[MersenneTwister][NewGenerator] depending on whether or not a number or procedure is to be returned.  It is more efficient to make these calls directly than to call rand.
 • The random number generator used by rand can be seeded by using the randomize or RandomTools[MersenneTwister][SetState] functions.
 • The use of the _seed global variable to seed the generator is deprecated.
 • The algorithm used by rand in Maple versions up to and including 9.5 has been moved into the RandomTools package as RandomTools[LinearCongruence].
 • To generate more complex Maple objects, the RandomTools[Generate] function can be used.
 • To sample from non-uniform probability distributions, the Statistics[Sample] function can be used.

Examples

 > $\mathrm{rand}\left(\right)$
 ${395718860534}$ (1)
 > $\mathrm{rand}\left(\right)$
 ${193139816415}$ (2)
 > $\mathrm{roll}≔\mathrm{rand}\left(1..6\right):$
 > $\mathrm{roll}\left(\right)$
 ${6}$ (3)
 > $\mathrm{roll}\left(\right)$
 ${2}$ (4)
 > $\mathrm{sampleFloat}≔\mathrm{rand}\left(1.0..6.0\right):$
 > $\mathrm{sampleFloat}\left(\right)$
 ${2.323567403}$ (5)
 > $\mathrm{sampleFloat}\left(\right)$
 ${1.809094426}$ (6)

Compatibility

 • The rand command was updated in Maple 2015.

 See Also