help-octave
[Top][All Lists]

 From: Mike Miller Subject: bad random numbers Date: Tue, 13 Jul 1999 01:21:25 -0500 (CDT)

```Maybe I have misunderstood octave's random number generator, but I thought
it produced numbers distributed uniformly on the interval from zero to
one.  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!

Unless I'm missing something obvious here, this is a very serious problem.
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).

Mike

--
Michael B. Miller
University of Missouri--Columbia
http://taxa.psyc.missouri.edu/~mbmiller/

#!/usr/local/bin/octave -q
rand(3)
ans =

0.0031259  0.0757851  0.8466739
0.9006672  0.8019347  0.5172935
0.3941688  0.7059492  0.4452699

ans =

0.0049122  0.4048052  0.9019161
0.2724771  0.8316117  0.8128898
0.7622653  0.1093487  0.2711385

ans =

0.0080381  0.4805903  0.7485901
0.1731443  0.6335464  0.3301833
0.1564340  0.8152979  0.7164084

ans =

0.0089312  0.6451004  0.2762112
0.8590491  0.1483848  0.4779814
0.8404822  0.0169977  0.1293427

ans =

0.010271  0.391865  0.067643
0.387907  0.920643  0.699679
0.866555  0.319547  0.748744

ans =

0.014736  0.214416  0.705748
0.817431  0.494835  0.438669
0.286796  0.328046  0.813415

ans =

0.0156296  0.3789255  0.2333696
0.5033360  0.0096735  0.5864674
0.9708440  0.5297459  0.2263496

ans =

0.016969  0.125691  0.024801
0.032193  0.781931  0.808165
0.996916  0.832295  0.845751

---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.  To ensure