You are on page 1of 3

Course Name: Modelling and Simulation Lab Course code: CSP-443

Experiment: 1.1
Aim: Write a program to implement a random number generator

Tools/Software Required: Matlab Mathworks and Personal Computer

Description: Random generator is used to generate the random number as per the functions
provided. Use the rand, randn, and randi functions to create sequences of pseudorandom numbers, and
the randperm function to create a vector of randomly permuted integers.

Pseudo code/Algorithms/Flowchart/Steps:
1. Open Matlab Mathworks
2. Create a new file
3. Implement the code
4. Save the file and run the code

Implementation:
1. rand(): This function returns the random number without

any range provided.

>>rand()

2. rand(m,n): This function returns the matrix of m*n random

numbers.

>>rand(3,4)

3. randi(n): This function returns the random integer upto the

limit provided(here it is n).

>>randi(6) or randi(2,5)

Name: Rohit Sharma UID:19BCS2700


4. randperm(n): This function returns the random permutation

of the numbers from 1 to n.

>>randperm(5)

5. randn(): This function returns the random number whether


it is positive or negative. Its mean will be 0 and deviation will be 1.
>>randn(7) or rand()

6. (b-a)*rand()+a: This function returns the random number

within the range from a to b. >>(900-100)*rand()+100

Output:

1.

2.

3.

4.

Name: Rohit Sharma UID:19BCS2700


5.

6.

Name: Rohit Sharma UID:19BCS2700

You might also like