help-octave
[Top][All Lists]
Advanced

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

Re: bad random numbers


From: Mike Miller
Subject: Re: bad random numbers
Date: Tue, 13 Jul 1999 19:41:56 -0500 (CDT)

On Tue, 13 Jul 1999, John W. Eaton wrote:

> | The results you produced show the same problem and it *is* a serious
> | problem.
> 
> It is not a serious problem for me, because I don't expect that there
> is any reason to believe that the sequence of numbers obtained by
> running
> 
>   while true; do echo rand | octave -qf; done
> 
> should have any special properties.


Like being random?  My "reason to believe" was that Octave documentation
states that a seed is produced from the system clock everytime Octave
starts.  This usually means that we get a different random number every
time we start the program.  That isn't what happens.



> | I don't understand how you're coding this.
> 
> Then you should look at the code.  It is pretty simple.
> 
> If you disagree with the method of setting the initial seed, then you
> are free to add some code to your startup files that will initialize
> it in a way that suits you.

I don't know C.  Maybe someone else will figure it out.  It seems to be in
the part of rand.cc appended below.  I now know how to avoid this bug, but
I would have thought that you would want to eliminate it so that it
doesn't affect the work of other users, and so that we don't have to add
an extra command every time we start the random number generator.

Mike



// Make the random number generator give us a different sequence every
// time we start octave unless we specifically set the seed.  The
// technique used below will cycle monthly, but it it does seem to
// work ok to give fairly different seeds each time Octave starts.

static void
do_initialization (void)
{
  time_t now;
  struct tm *tm;
 
  time (&now);
  tm = localtime (&now);
 
  int hour = tm->tm_hour + 1;
  int minute = tm->tm_min + 1;
  int second = tm->tm_sec + 1;

  int s0 = tm->tm_mday * hour * minute * second;
  int s1 = hour * minute * second;

  s0 = force_to_fit_range (s0, 1, 2147483563);
  s1 = force_to_fit_range (s1, 1, 2147483399);

  F77_XFCN (setall, SETALL, (s0, s1));

  initialized = 1;
}



---------------------------------------------------------------------
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]