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 4

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

Subject: Random number Generator Help

From: John D'Errico

Date: 25 Apr, 2009 12:38:01

Message: 2 of 4

"Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gsuqlb$3gp$1@fred.mathworks.com>...
> 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)

Hmm. Since all of these numbers are positive, do
you expect that I will grow without bound? (I
hope you will say yes.)

What is the largest number you can represent in
MATLAB as an exact integer? (If these are doubles,
you can up to 2^53).

Is your formula correct if you will expect these
numbers to stay bounded? (No.)

Should there be some form of modulo operator
in there? (One would imagine so.)

John

Subject: Random number Generator Help

From: Sid Hayes

Date: 25 Apr, 2009 21:14:02

Message: 3 of 4

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <gsv079$nag$1@fred.mathworks.com>...
> "Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gsuqlb$3gp$1@fred.mathworks.com>...
> > 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)
>
> Hmm. Since all of these numbers are positive, do
> you expect that I will grow without bound? (I
> hope you will say yes.)
>
> What is the largest number you can represent in
> MATLAB as an exact integer? (If these are doubles,
> you can up to 2^53).
>
> Is your formula correct if you will expect these
> numbers to stay bounded? (No.)
>
> Should there be some form of modulo operator
> in there? (One would imagine so.)
>
> John

Hi

Firstly, thanks for the reply!!

I think there is meant to be a modulo operator in there.

I was trying to bound the formula, so the function (I) would not increase as more random numbers are generated.

After, the random numbers are produced, these will then be coverted to binary numbers by using: bn = 0 if 0<Rn<0.5
                                = 1 if 0.5<Rn<1

Hope this can help.

Kind Regards
Sid

Subject: Random number Generator Help

From: Sid Hayes

Date: 25 Apr, 2009 22:56:00

Message: 4 of 4

"Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gsvueq$fai$1@fred.mathworks.com>...
> "John D'Errico" <woodchips@rochester.rr.com> wrote in message <gsv079$nag$1@fred.mathworks.com>...
> > "Sid Hayes" <sid.hayes@hotmail.com> wrote in message <gsuqlb$3gp$1@fred.mathworks.com>...
> > > 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)
> >
> > Hmm. Since all of these numbers are positive, do
> > you expect that I will grow without bound? (I
> > hope you will say yes.)
> >
> > What is the largest number you can represent in
> > MATLAB as an exact integer? (If these are doubles,
> > you can up to 2^53).
> >
> > Is your formula correct if you will expect these
> > numbers to stay bounded? (No.)
> >
> > Should there be some form of modulo operator
> > in there? (One would imagine so.)
> >
> > John
>
> Hi
>
> Firstly, thanks for the reply!!
>
> I think there is meant to be a modulo operator in there.
>
> I was trying to bound the formula, so the function (I) would not increase as more random numbers are generated.
>
> After, the random numbers are produced, these will then be coverted to binary numbers by using: bn = 0 if 0<Rn<0.5
> = 1 if 0.5<Rn<1
>
> Hope this can help.
>
> Kind Regards
> Sid

ANY ADVICE ON HOW BEST TO APPROACH WHAT IM TRYING TO DO??

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