|
|
Function: random (x)
- Generation of a pseudorandom number
- random (x) returns an integer from 0 through x - 1 inclusive.
Example:
(%i ) random(10);
(%o )5
(%i ) random(10);
(%o )8
(%i ) random(10);
(%o )1
(%i ) random(10.0);
(%o ) 4.155627227214829
(%i7) random(10.0);
(%o ) 6.125738892538246
(%i ) random(10.0);
(%o ) 8.418126553359214
(%i ) n: 10000$
(%i ) c: 0$
(%i ) for i: 1 thru n do if (random(1.0)^2 + random(1.0)^2 < 1) then c: c + 1;
(%o ) done
(%i ) float(4 * c / n);
(%o ) 3.1348
(%i ) s: make_random_state(true);
(%o ) Structure [RANDOM-STATE]
(%i ) set_random_state( s );
(%o ) done
linel is the assumed width (in characters) of the console display for the purpose of displaying expressions.
See Also:
-
OCTAVE
::
RAND ... Uniform Distribution Random Elements Generation
-
OCTAVE
::
RANDN ... Normal Distribution Random Elements Generation
|
|
|