Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Random number Generator Help

Subject: Random number Generator Help

From: Sid Hayes

Date: 25 Apr, 2009 11:03:07

Message: 1 of 1

Hi,

I am trying to create a specific RNG.

using values: un =064265094
                   cn =656992
                   tn =1064265094

my RNg will be: I(n+1)=[cn*I(n) + un*I(n-1)]*(tn)

we can choose I(1) and I(2) as any seven digit number.

This is my algorithm so far.

% Undergraduate Number: Un = 064265094
% Candidate Number : Cn = 656992
% Card Number : Tn = 1064265094

% RNG i will be using is: I(n+1) = [CnI(n) + UnI(n-1)](Tn)

% Initial Conditions i will choose are: I(1) = 7836998
% I(2) = 2431625

% Question A
% Write a program which computes the sequence J = {Rn}, Where Rn=I(n)/Tn
N = input('Enter Number of Rn Required: ');
I = ones(N,1); %Defines basis for I's as a matrix.
I(1) = 7836998;
I(2) = 2345678;

Cn = 656992;
Un = 64265094;
Tn = 1064265094;

% The RNG
for n = 2:N-1
    I(n+1) = ( ( Cn * I(n) ) + ( Un * I(n-1) ) ) * (Tn);
end

% Compute Sequence of J = {Rn}
R = ones(N,1); %Defines basis for R's as a matrix.
for n = 1:N
    R(n) = I(n)/Tn;
end

The problem i face is, from I(3) onward the values are far greater then 1, which is not what i want.

Can you help me please.

Cheers
Sid

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us