12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

158 <strong>GNU</strong> <strong>Octave</strong>rand (x)Loadable Functionrand (n, m)Loadable Functionrand ("seed", x)Loadable FunctionReturn a matrix with random elements uniformly distributed on the interval (0, 1).The arguments are handled the same as the arguments for eye. In addition, you canset the seed for the random number generator using the formrand ("seed", x)where x is a scalar value. If called asrand ("seed")rand returns the current value of the seed.randn (x)Loadable Functionrandn (n, m)Loadable Functionrandn ("seed", x)Loadable FunctionReturn a matrix with normally distributed random elements. The arguments arehandled the same as the arguments for eye. In addition, you can set the seed for therandom number generator using the formrandn ("seed", x)where x is a scalar value. If called asrandn ("seed")randn returns the current value of the seed.The rand and randn functions use separate generators. This ensures thatrand ("seed", 13);randn ("seed", 13);u = rand (100, 1);n = randn (100, 1);andrand ("seed", 13);randn ("seed", 13);u = zeros (100, 1);n = zeros (100, 1);for i = 1:100u(i) = rand ();n(i) = randn ();endproduce equivalent results.Normally, rand and randn obtain their initial seeds from the system clock, so that thesequence of random numbers is not the same each time you run <strong>Octave</strong>. If you really doneed for to reproduce a sequence of numbers exactly, you can set the seed to a specific value.If it is invoked without arguments, rand and randn return a single element of a randomsequence.The rand and randn functions use Fortran code from Ranlib, a library of fortranroutines for random number generation, compiled by Barry W. Brown and James Lovatoof the Department of Biomathematics at The University of Texas, M.D. Anderson CancerCenter, Houston, TX 77030.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!