Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

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.6324

MATLAB 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.8003

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS