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 formulæ. T

ID: 2257315 • Letter: R

Question

Random numbers are usually computed using simple discrete mathematics formulæ. The linear congruential generator is described by the formula Xn+1 = (ax + c) mod m where a, c and m are parameters of the generator with Xn being the previous random number and Xn+1 being the next random number. Xo 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,515,245 C = 12,345 m = 231 -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 altask7.m that implements the above method and assigns the seed 23,948. This script is to compute the next five random numbers and print them in the format RN1=, RN2=, ... RN5=. Include this file in your zip archive.

Explanation / Answer

a2task7.m

close all
clear
clc

a = 1103515245;
c = 12345;
m = 2^31 - 1;
x = 23948;
for i=1:5
x = rem(a*x + c, m);
fprintf('RN%d=%d ',i,x);
end

output

RN1=49339623
RN2=654933792
RN3=177626538
RN4=1937547333
RN5=1520150509