help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Same sequence of random number generators than under Matlab?


From: Mathieu Dubois
Subject: Re: Same sequence of random number generators than under Matlab?
Date: Tue, 05 Jun 2012 13:59:56 +0200 (CEST)

----- Mail original -----
De: "Alasdair McAndrew" <address@hidden>
À: "Mathieu Dubois" <address@hidden>, address@hidden
Envoyé: Lundi 4 Juin 2012 14:26:00
Objet: Re: Same sequence of random number generators than under Matlab?


> Writing your own is a good idea. Cleve Moler, here, speaks of the linear 
> congruential generator


> x_{k+1} = ax_k (mod m)


> with a,m = 16807, 2^31-1

I tried to implement the algorithm (see attached file) but it doesn't seem to 
work (I get sequences containing 0). Can somebody help?

Just a note: I'm trying to mimck the behaviour of Matlab rand function. My plan 
is to put the file in the test directory (under the name 'rand.m') so that the 
rand function will be replaced by my implementation. This is because I don't 
want to touch the code of the toolbox I'm using. As this toolbox uses 
rand('state', seed) my code tries to mimick that (this is also why I don't want 
ti implement more complicated algorithm that use a vector of seeds). The code 
uses a global variable for the seed and for xn which is the next random number 
to return. I print the state of the genrator at the begining and end of the 
function.

Thanks in advance for any help,
Mathieu

Attachment: my_rand.m
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]