help-octave
[Top][All Lists]
Advanced

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

Re: bad random numbers


From: John Judge
Subject: Re: bad random numbers
Date: Wed, 14 Jul 1999 13:30:53 +1000 (EST)

Mike,

On Tue, 13 Jul 1999, Mike Miller wrote:

> echo 'rand(3)' | octave -q
> echo 'rand("seed",time);rand(3)' | octave -q
> 
> Question:  If rand gets its seed from the clock when octave starts, then
> why does the first command line above give aberrant results while the
> second command works beautifully?
> 

The difference appears to be the value used in the seeding. The first
command uses the seed calculated in the code fragment shown in the
earlier email which is based on the integer value of epoch seconds. The
second command uses a seed based on the builtin function time which
returns a double based on epoch seconds and microseconds. Using 2.0.14
I get:

octave:9> for i = 1:10
> printf("%f\n", time);
> endfor
931922099.301045
931922099.301411
931922099.301682
931922099.301951
931922099.302221
931922099.302490
931922099.302763
931922099.303038
931922099.303316
931922099.303587

I think you will find the undesirable result if you change the second
command to:

echo 'rand("seed",floor(time));rand(3)' | octave -q

John Judge
Research Manager                            email : address@hidden
TITR                                        phone : +61 42 21 4442
University of Wollongong                    fax   : +61 42 21 3277



---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------



reply via email to

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