PRN in Matlab - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

PRN in Matlab

uniden6000uniden6000 Posts: 2Member
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

Thanks in advance

Comments

  • giuggiug Posts: 217Member
    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.

    So, in your code:

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

    x([b]1[/b]) = 1234;

    for k = [b]1[/b]:100
    x(k+1) = mod(a*x(k) + b,m);
    end
Sign In or Register to comment.