You are on page 1of 2

Worksheet 2

Student Name:Peacon Pramanik


Puran Kumar UID:19bcs2056
19BCS2059
Branch:CSE Section/Group: 19/A
Semester:7th Date of Performance:8/8/22
Subject Name: Modelling & Stimulation Subject Code:CSP-443

1. Aim/Overview of the practical: Write a program to implement linear congruential


generator

2. Objective : Apply the knowledge of Modelling and Simulation to implement the basic
components like random number generator, linear congruential generator, etc

3. Software/Apparatus Required: MATLAB R2013A, Personal computer

4. Algorithm/Flowchart :

a) Choose the seed value Xo , Modulus parameter m, Multiplier term a ,


and increment term c.
b) Initialize the required amount of random numbers to generate (say, an
integer variable noOfRandomNums).
c) Define a storage to keep the generated random numbers (here , vector is
considered )of size noOfRandomNums.
d) Intialize the 0 th index of the vector with the seed value.
e) For rest of the indexes follow the Linear Congruential Method to
generate the random numbers.

5. Code for experiment/practical:

a=19;
b=-3332;
m=2^13;
f=@(x) mod((a*x)+b,m);
x(1)=1;
for i=1:m
x(i+1)=f(x(i));

end
x
d=0;
for i=1:m
if x(i+1)==x(1)
d=i;
break;
end
end

6. Result/Output/Writing Summary:

Learning outcomes (What I have learnt):

1. How to use Matlab software

2. What’s Linear congruential method

3. Varioius ways to generating random numbers in matlab

4. Various new keywords in matlab programing

You might also like