help-octave
[Top][All Lists]
Advanced

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

Re: rand("state")


From: Bill Denney
Subject: Re: rand("state")
Date: Wed, 15 Feb 2006 14:09:20 -0500 (EST)

On Wed, 15 Feb 2006, Mike Miller wrote:

On my system, rand("state"), using Octave-Forge rand.oct, returns a row vector of 625 integers. (By the way, the "help rand" doc says that it is a column vector.) The interesting thing is that the integers seem to be uniformly distributed with a max of about 2^32, but the 625th integer seems to be different from the others with a mean somewhere around 300 or so. What is rand("state")(625) doing?

If I remember correctly, the way that the random number generator works is with a Mersenne Twister algorithm. This algorithm uses what is called an incomplete matrix calculation and one of the rows of the matrix is shorter than others. I think that's why the last number is smaller.

I'm interested in this because I want to do a simulation project with 100 seeds and I want to choose the seeds before I start so that the whole simulation of 100 replicates can be duplicated later. I was thinking that maybe this would make a good set of seeds for me:

stored_seeds = ceil( rand( 100, 625 ) * 2^32 );

I could then store the seeds in a file and import them as needed. Then I would do this at the beginning of a replicate:

rand ("state", stored_seeds( rep, : ) )

Where "rep" is a scalar holding the replicate number.

At this point, it all looks right to me except for the 625th integer in each seed.

This is a question for someone else, but my suggestion would be to try out seeding with one seed and see if the numbers come out the same every time. My guess would be that the seeding algorithm would just chop off any extra bits that are unnecessary in the last number.

One thing to watch out for is that you probably want to be sure that you get different seeds every time you generate them if you have to generate them in more than one octave session. A good place to get true random numbers for your seed is www.random.org.

Bill

--
"You have reached the pinnacle of success as soon as you become
uninterested in money, compliments, or publicity."
  -- Thomas Wolfe



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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