MATLAB Answers

Using Linear congruential to generate 10,000 uniform random variables

6 views (last 30 days)
I want to generate uniform random variables between 0 and 1 by using X(n+1)=(1664525*X(n)+1013904223) mod^32, but i couldn't.
Please help...
this is my code:
clear all; clc;
a=1664525; c=1013904223; m=2^32;
for n=1:10000
X(n)=mod((a*X(n)+c), m);
end
disp(X);

  0 Comments

Sign in to comment.

Accepted Answer

Alan Stevens
Alan Stevens on 27 Nov 2020
You need an intial value for X(1); and you need to set
for n=2:10000
X(n+1)=mod((a*X(n)+c), m);
end

  7 Comments

Show 4 older comments
Beom soo Kim
Beom soo Kim on 27 Nov 2020
With your help, it is getting amazingly better! Thanks a lot.
I still have one (hope to be) problem, that my variables are going up to 4.5, which I want to make it in between 0 to 1.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by