Generating Random Numbers

The rand function in MATLAB generates random numbers in MATLAB. 

Syntax:

num = rand(<optional parameters>)

The rand function generates uniformly distributed random numbers (real numbers) in the range of (0,1).

Example 1:

Matlab




% MATLAB code 
for i = 1:5
    ran_num = rand;
    disp(ran_num)
end


Output:

 

The above code generates 5 random numbers and displays them using the disp() function.

Random Numbers in MATLAB

Random numbers, as the name suggests, are numbers chosen randomly from a set of numbers. In practical application, classical computers cannot create truly random numbers as they are developed on binary logic thus, they require some sort of algorithm to generate random numbers, this type of random number is called a pseudorandom number. They are random numbers generated by an algorithm in the core of a given programming language by using some variable such as system time, which will never be the same, as a seed to produce different numbers every time.

In MATLAB, there are plenty of options to generate random numbers of different types. This article will discuss how to generate random numbers with various options available in MATLAB.

Similar Reads

Generating Random Numbers:

The rand function in MATLAB generates random numbers in MATLAB....

Square Matrix of Random Numbers:

...

Generating Random Numbers in Any Range (min, max):

To generate an n-order matrix of random numbers in the range (0,1), we use the following method....

Contact Us