Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Random numbers are usually computed using simple discrete mathematics formula. T

ID: 3111974 • Letter: R

Question

Random numbers are usually computed using simple discrete mathematics formula. The linear congruential generator is described by the formula X_n+1 = {a X_n + c} mod m where a, c and m are parameters of the generator with X_n being the previous random number and X_n + 1 being the next random number. X_0 is referred to as the seed. This algorithm is used extensively throughout the computing world, e.g., the random number generator implemented by C and available in glibc has parametric values a = 1, 103, 5 15, 245 c = 12, 345 m = 2^31-1 Numerical random number generators are not random: they are deterministic. Given a seed, the sequence of random numbers will be the same. They are referred to as being pseudo-random because they seem to behave as randomly generated. Write a MatLab script a2task7.m that implements the above method and assigns the seed 314, 159. This script is to compute the next five random numbers and store them into variables RN1, RN2, ..., RN5.

Explanation / Answer

%%% Matlab code %%%%%%%%

clc;
clear all;
close all;
format long
a=1103515245;
c=12345;
m=2^(31)-1;
x(1)=314149;
for n=1:5
    y=a*x(n)+c;
    x(n+1)=mod(y,m);
end
RN1=x(2);
RN2=x(3);
RN3=x(4);
RN4=x(5);
RN5=x(6);