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: Tue, 27 Apr 2004 20:52:34 -0400

Daniel,

seed/state behaviour is from octave-forge.  The behaviour you
describe below seems to be from octave' versions.  I'm confused
about what you are using.

The seed/state behaviour is there for compatibility.  It is in
matlab because they changed their generator at some point,
and probably didn't want to break existing code or change
their documentation examples.  In octave-forge seed and
state use the same generator, but they will yield different
sequences.

The problems you describe below occur for me as well
on octave-2.1.55 for mac os x.  octave-forge's generators
do not have these problems.

Paul Kienzle
address@hidden

On Apr 27, 2004, at 4:51 PM, Daniel J Sebald wrote:

Just a few comments about the current behavior of the rand/randn functions...

I upgraded from 2.1.46 (very confusing and peculiar "seed"/"state" behavior) to 2.1.57. I'm glad in the documentation that it is pointed out that rand and randn have separate generators. There was no such documentation in 2.1.46, which I think had just a single psuedo random number generator. Anyway, I'm trying to record the seed so that I can reproduce simulation results at a later date. So, the idea is that one should be able to do a

s = rand("seed")

and get the value of the seed. If one keeps a record of the answer, then

rand("seed",s);

should restore to the proper state. OK, this does seem to work as far as I can tell. But the fact that the answer to rand("seed") is in float means that the number will have to be saved in a file to actually restore the value because of the potential loss of precision. All I'm saying is that the following may lead to slight confusion to an inexperienced user, i.e., the fact that the seed isn't restored properly:

octave:76> rand("seed")
ans = 2.6677e+167
octave:77> rand
ans = 0.64748
octave:78> rand("seed",2.6677e+167)
octave:79> rand
ans = 0.31050

Of course, the smart thing would be to always choose the seed one's-self from the start so that such confusion couldn't arise.

A few minor things...

Here is the result of rand("seed",0):

octave:70> rand("seed",0)
octave:71> rand("seed")
ans = 2.1220e-314

I assume that the answer given is the smallest possible number. (There is a zero in floating point 'though, isn't there?) Also,

octave:89> rand("seed",Inf)
octave:90> rand("seed")
ans = NaN

whereas

octave:92> rand("seed",NaN)
octave:93> rand("seed")
ans = 1.1125e-308


In the documentation under "help -i" for "rand/randn" is some newly added text that doesn't seem to follow the indentation rules of all the other documentation. That is, there are lines like:

  The `rand' and `randn' functions use separate generators.  This
ensures that

where the carriage return is part of the text, not part of the command line width. The text should be indented further to the right.

There is a typo in the line (i.e., drop the "for"):

Dan





reply via email to

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