Generating Random Numbers
The rand function
returns uniformly distributed random numbers between 0 and 1.
rand(1,5)
ans =
0.8147 0.9058 0.1270 0.9134 0.6324MATLAB software initializes a default stream at startup.
The rand function
accesses the default stream and draws a set of numbers to create the
output. This means that every time rand is
called, the state of the default stream is changed and the output
is different.
A=rand(1,5);B=rand(1,5);
A,B
A =
0.0975 0.2785 0.5469 0.9575 0.9649
B =
0.1576 0.9706 0.9572 0.4854 0.8003rand returns
pseudorandom numbers from a uniform distribution.
randn returns
pseudorandom numbers from a normal distribution.
randi returns
pseudorandom numbers from a uniform discrete distribution.
 | Random Numbers | | Managing the Default Stream |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit