In: Advanced Math
Propose two of your own random number generation schemes. Please generate 100 random numbers ?? (? = 1,2, … ,100) for each scheme and show the results on the same plot for comparison (i.e., x-axis of the plot will show the index ? and y-axis will show the generated random numbers ??. You can use different colors and/or symbols to distinguish one sequence from the other). Discuss which scheme will be preferred.
%%Matlab code for Random number generation
clear all
close all
%Linear congruential generator
a=343234;
b=432523;
m=999999;
x=1;
for i=1:100
y1(i)=mod(a*x+b,m);
x=y1(i);
end
xx=1:100;
plot(xx,y1,'bo','linewidth',2)
%Middle square method
seed=213456;
for i=1:100
x=seed^2;
y=num2str(x);
ln=length(y);
if ln<=12
y(ln+1:12)=num2str(0);
end
y2(i)=str2num(y(4:9));
seed=y2(i);
end
hold on
plot(xx,y2,'r*','linewidth',2)
xlabel('i')
ylabel('y(i)')
title('Random number with two different methods')
legend('Linear congruential','Middle square method')
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%