help-octave
[Top][All Lists]
Advanced

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

Re: Difference between random number seed between octave and matlab


From: Nicholas Jankowski
Subject: Re: Difference between random number seed between octave and matlab
Date: Sat, 22 Jun 2013 21:40:13 -0400

details on Matlab's randn function can be found here:
http://www.mathworks.com/help/matlab/ref/randn.html

it states that the rng function controls the seed. that can be found here:
http://www.mathworks.com/help/matlab/ref/rng.html

looking at the documentation on Octave's rand(), I find the following
http://www.gnu.org/software/octave/doc/interpreter/Special-Utility-Matrices.html#Special-Utility-Matrices

"By default, the generator is initialized from /dev/urandom if it is available, otherwise from CPU time, wall clock time, and the current fraction of a second. "

So, it seems that is an incompatibility between the two programs, unless i'm missing something. You can call octave's rand in a way that will produce repeatable values, but seems like in Matlab you have to seed rng, which then affects rand...


nickj


On Sat, Jun 22, 2013 at 9:23 PM, Peng Yu <address@hidden> wrote:
Hi,

It seems that each time matlab starts, it uses the same seed but
octave does not. See below for demonstration. (mlb.sh is just a
wrapper to matlab so that it accept input from stdin.) Does anybody
where this is documented in matlab and octave?

~/linux/test/octave/matlab/lang/function/randn$ cat main.m
#!/usr/bin/env bash
shopt -s lastpipe; tail -n +3 "$0" | exec /usr/bin/env mlb.sh

randn
~/linux/test/octave/matlab/lang/function/randn$ ./main.m
>> >>
ans =

    0.5377

~/linux/test/octave/matlab/lang/function/randn$ ./main.m
>> >>
ans =

    0.5377

~/linux/test/octave/octave/lang/function/randn$ ./main.m
ans =  1.1670
ans =

  -0.24059   0.84457   2.06545
   2.57006  -1.60635   0.37254
   0.82313   0.18364  -1.61877

ans =

   0.345635   0.714953   0.022038  -0.939530
  -1.114125   0.135750  -1.117729   1.749078
  -0.245421   0.299924  -0.634159   0.773315

~/linux/test/octave/octave/lang/function/randn$ ./main.m
ans =  0.45906
ans =

   1.4029686  -0.0407457  -0.1168094
  -1.1502772  -1.2197264  -0.8701638
   0.0082042   0.8846563  -1.4461442

ans =

  -1.007959  -0.686997   1.465105  -0.347564
   0.640916  -1.456063   0.866900  -0.784564
  -0.549065  -0.051180   0.249265   0.755601

~/linux/test/octave/octave/lang/function/randn$ cat main.m
#!/usr/bin/env octave -q

randn
randn(3)
randn(3, 4)


--
Regards,
Peng
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


reply via email to

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