## Matlab

Moderators: None (Apply to moderate this forum)
Number of posts: 2178

This Forum Only

PRN in Matlab Posted by uniden6000 on 12 Apr 2009 at 7:25 PM
I have to write a Pseudo random number generator with matlab, but I don't know how to start.

This is the equation:

Xk+1 = [711*Xk + 37]mod10000 and xo = 1234

I know that I need to write a loop statement, but I don't know how to do it. Also, what is "mod" and is there a statement in matlab to find the it?

This is what I've done, but it doesn't work
m = 1000;
a = 711;
b = 37;

x(0) = 1234;

for k = 0:100
x(k+1) = mod(a*x(k) + b,m);
end

Re: PRN in Matlab Posted by giug on 12 Apr 2009 at 11:54 PM
Your code is ok, there is only an error. In matlab the first element of a vector is x(1) not x(0) that doesn't exist (for this reason it gives you an error.

m = 1000;
a = 711;
b = 37;

x(1) = 1234;

for k = 1:100
x(k+1) = mod(a*x(k) + b,m);
end

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic