Contents Previous Next Subchapters

Generating Uniformly Distributed Pseudo Random Numbers
Syntax rand(rows)
rand(rowscols)
See Also unirnd , normrnd , randperm

Description
Returns a real matrix containing random elements that are uniformly distributed between 0 and 1, where rows is the number of rows and cols is the number of columns. The arguments rows and cols are integer, real, double-precision or complex scalars. If an argument is complex, only its real part is used. If the argument cols is not present, a square matrix is returned.

Example
     clear
     rand(3, 1)
results in
     {
     4.65661e-010
     0.527357
     0.384887
     }
The rand function returns values from a pseudo-random sequence. It always starts at the same point at the beginning of an O-Matrix session and after a clear. If you continue the previous example by entering
     clear
     rand(3, 1)
O-Matrix will respond
     {
     4.65661e-010
     0.527357
     0.384887
     }
which are the same as the numbers output above. If, however, you continue the previous example (without clearing) by entering
     rand(3, 1)
O-Matrix will respond
     {
     0.134948
     0.223919
     0.643237
     }
which is a different set of numbers.

Reference
The arguments must be scalars. If they are logical, real, double-precision or complex, the corresponding integer values are used.