rand

Returns a random floating point number or vector within a range of your choice.

float rand(float maxnumber)

float rand(float minnumber, float maxnumber)

vector rand(vector maxvector)

vector rand(vector minvector, vector maxvector)

maxnumber specifies the maximum number returned (in the first syntax format listed above). The minimum number returned is 0. In other words, the returned value will be a random number between 0 and maxnumber.

minnumber and maxnumber specify the minimum and maximum numbers returned.

maxvector specifies the maximum value for each component of the vector returned. The minimum value is 0. Each component returned is a different random number.

minvector and maxvector specify the minimum and maximum value for each component of the vector returned.

To control the random values returned by this function, see seed.

Example 1

rand(5)

Returns a random floating point number between 0 and 5, for example, 3.539.

Example 2

rand(-1,1)

Returns a random floating point number between -1 and 1, for example, 0.452.

If you were to execute rand(-1,1) repeatedly as an animation plays, its return values might occur as in this figure:

Example 3

rand(<<1,1,1>>)

Returns a random vector in which each component is between 0 and 1, for example, <<0.532, 0.984, 0.399>>.

Example 4

rand(<<1,1,1>>,<<100,200,300>>)

Returns a random vector in which the left component is between 1 and 100, the middle component is between 1 and 200, and the right component is between 1 and 300. An example is <<81.234, 49.095, 166.048>>.