(maxima.info)Random Numbers


Prev: Trigonometric Functions Up: Mathematical Functions
Enter node , (file) or (file)node

10.6 Random Numbers
===================

 -- Function: make_random_state
          make_random_state (<n>)
          make_random_state (<s>)
          make_random_state (true)
          make_random_state (false)

     A random state object represents the state of the random number
     generator.  The state comprises 627 32-bit words.

     'make_random_state (<n>)' returns a new random state object created
     from an integer seed value equal to <n> modulo 2^32.  <n> may be
     negative.

     'make_random_state (<s>)' returns a copy of the random state <s>.

     'make_random_state (true)' returns a new random state object, using
     the current computer clock time as the seed.

     'make_random_state (false)' returns a copy of the current state of
     the random number generator.

 -- Function: set_random_state (<s>)

     Copies <s> to the random number generator state.

     'set_random_state' always returns 'done'.

 -- Function: random (<x>)

     Returns a pseudorandom number.  If <x> is an integer, 'random
     (<x>)' returns an integer from 0 through '<x> - 1' inclusive.  If
     <x> is a floating point number, 'random (<x>)' returns a
     nonnegative floating point number less than <x>.  'random'
     complains with an error if <x> is neither an integer nor a float,
     or if <x> is not positive.

     The functions 'make_random_state' and 'set_random_state' maintain
     the state of the random number generator.

     The Maxima random number generator is an implementation of the
     Mersenne twister MT 19937.

     Examples:

          (%i1) s1: make_random_state (654321)$
          (%i2) set_random_state (s1);
          (%o2)                         done
          (%i3) random (1000);
          (%o3)                          768
          (%i4) random (9573684);
          (%o4)                        7657880
          (%i5) random (2^75);
          (%o5)                11804491615036831636390
          (%i6) s2: make_random_state (false)$
          (%i7) random (1.0);
          (%o7)                  0.2310127244107132
          (%i8) random (10.0);
          (%o8)                   4.394553645870825
          (%i9) random (100.0);
          (%o9)                   32.28666704056853
          (%i10) set_random_state (s2);
          (%o10)                        done
          (%i11) random (1.0);
          (%o11)                 0.2310127244107132
          (%i12) random (10.0);
          (%o12)                  4.394553645870825
          (%i13) random (100.0);
          (%o13)                  32.28666704056853


automatically generated by info2www version 1.2.2.9