octave-maintainers
[Top][All Lists]
Advanced

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

Re: rand seed


From: Paul Kienzle
Subject: Re: rand seed
Date: Wed, 28 Apr 2004 06:27:47 -0400


On Apr 28, 2004, at 3:53 AM, Daniel J Sebald wrote:

... the original problem I was seeing with the version of the
random number generator that has "seed" or "state" is that
successive commands of

rand("seed")

kept spitting out a different number, which it shouldn't do.

Yes, I'm aware of that.  However I contend that the behaviour
is not incorrect.  You will see that
        v = rand("seed"); x = rand(10,1);
        rand("seed",v); y = rand(10,1);
        any(x!=y)
returns false.  That is, if you capture a seed, then it will always
generate the same sequence.  That is true even if your set of
operations includes calls to rand("seed").  So if you set up a
demo starting from a particular random number, you will be able
to replay that demo and get the same result.

You are correct, though, that you can't observe the seed without
disturbing the current state.  That's because the state is really a
large vector which I cannot capture in 53 bits.  So instead, a call
to seed returns a random number and resets the state vector
based on that value.  When you later call rand("seed",v), it again
resets the state vector based on that value.

I could fake it and keep track of whether the last rand operation
was a call to rand("seed"), and return the same seed if that is
the case.  Is this really worth while?

Also

rand("seed",v)

never seemed to get me back to the same state.

The above code works for me.  The generator is in the same
state, it is just not reporting it to you.

However,

rand("state",v)

did seem to work so long as v was gotten from

v = rand("state");

State returns the entire state, so it works like you expect.

Paul Kienzle
address@hidden



reply via email to

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