help-octave
[Top][All Lists]
Advanced

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

bad random numbers


From: John W. Eaton
Subject: bad random numbers
Date: Tue, 13 Jul 1999 14:58:07 -0500 (CDT)

On 13-Jul-1999, Mike Miller <address@hidden> wrote:

| Maybe I have misunderstood octave's random number generator, but I thought
| it produced numbers distributed uniformly on the interval from zero to
| one.

It should.  It is based on randlib.  You can get the sources and the
docs for the randlib library with Octave's source distribution.

| As an exercise, I wrote a little octave script (shown below) and
| executed it a few times.  This script should produce a matrix of
| independent and identically distributed random numbers between zero and
| one.  Note that the resulting matrix always had a very small number in the
| 1,1 cell.  The value in that cell ranged from .003 to .017 and the value
| increased over the eight trial runs.  Yikes!

The initial seeds for rand are computed from time().  Not random
itself, but at least it should be different each time you run Octave.
Here is a sequence of runs on my system:

  bash:127> echo "rand (3)" | octave -qf
  ans =

    0.35202  0.32636  0.76954
    0.78519  0.16961  0.68034
    0.15899  0.68584  0.50857

  bash:128> echo "rand (3)" | octave -qf
  ans =

    0.509432  0.071253  0.262760
    0.425929  0.909894  0.729762
    0.722494  0.235420  0.788238

  bash:129> echo "rand (3)" | octave -qf
  ans =

    0.666845  0.816146  0.755982
    0.066669  0.650177  0.779184
    0.285993  0.785003  0.067902

  bash:130> echo "rand (3)" | octave -qf
  ans =

    0.82426  0.56104  0.24920
    0.70741  0.39046  0.82861
    0.84949  0.33459  0.34757


| Unless I'm missing something obvious here, this is a very serious
| problem.

Can you elaborate?  What is serious about it?  You are looking at a
really small sample of numbers returned from the the generator.  If
you ask for a larger sample, I think you will find that they are
normally distributed.

| I ran the script many more times with similarly disturbing results -- the
| sequence continued until the 1,1 cell exceeded .25, then it dropped to a
| small value again and began to increase from there.  I'm running Octave
| 2.0.13 on Solaris 2.6.
| 
| By the way, I don't see this behavior when I run rand(3) repeatedly from
| the octave prompt.  There it looks OK, but it still gives either 5 or 6 or
| 7 digits behind the decimal for each number in a haphazard way (like
| below).

The number of digits displayed is due to the way that Octave tries to
display numbers without dropping precision.  For example, try

  x = [0.123456789; 1.23456789];
  for y = 10.^(-4:4); x/y, end

jwe



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