GNU Info

Info Node: (slib.info)Random Numbers

(slib.info)Random Numbers


Next: Fast Fourier Transform Prev: Prime Numbers Up: Mathematical Packages
Enter node , (file) or (file)node

Random Numbers
==============

  `(require 'random)'

  A pseudo-random number generator is only as good as the tests it
passes.  George Marsaglia of Florida State University developed a
battery of tests named "DIEHARD"
(<http://stat.fsu.edu/~geo/diehard.html>).  `diehard.c' has a bug which
the patch
<http://swissnet.ai.mit.edu/ftpdir/users/jaffer/diehard.c.pat> corrects.

  SLIB's new PRNG generates 8 bits at a time.  With the degenerate seed
`0', the numbers generated pass DIEHARD; but when bits are combined
from sequential bytes, tests fail.  With the seed
`http://swissnet.ai.mit.edu/~jaffer/SLIB.html', all of those tests pass.

 - Function: random n
 - Function: random n state
     Accepts a positive integer or real N and returns a number of the
     same type between zero (inclusive) and N (exclusive).  The values
     returned by `random' are uniformly distributed from 0 to N.

     The optional argument STATE must be of the type returned by
     `(seed->random-state)' or `(make-random-state)'.  It defaults to
     the value of the variable `*random-state*'.  This object is used
     to maintain the state of the pseudo-random-number generator and is
     altered as a side effect of calls to `random'.

 - Variable: *random-state*
     Holds a data structure that encodes the internal state of the
     random-number generator that `random' uses by default.  The nature
     of this data structure is implementation-dependent.  It may be
     printed out and successfully read back in, but may or may not
     function correctly as a random-number state object in another
     implementation.

 - Function: copy-random-state state
     Returns a new copy of argument STATE.

 - Function: copy-random-state
     Returns a new copy of `*random-state*'.

 - Function: seed->random-state seed
     Returns a new object of type suitable for use as the value of the
     variable `*random-state*' or as a second argument to `random'.
     The number or string SEED is used to initialize the state.  If
     `seed->random-state' is called twice with arguments which are
     `equal?', then the returned data structures will be `equal?'.
     Calling `seed->random-state' with unequal arguments will nearly
     always return unequal states.

 - Function: make-random-state
 - Function: make-random-state obj
     Returns a new object of type suitable for use as the value of the
     variable `*random-state*' or as a second argument to `random'.  If
     the optional argument OBJ is given, it should be a printable
     Scheme object; the first 50 characters of its printed
     representation will be used as the seed.  Otherwise the value of
     `*random-state*' is used as the seed.

  If inexact numbers are supported by the Scheme implementation,
`randinex.scm' will be loaded as well.  `randinex.scm' contains
procedures for generating inexact distributions.

 - Function: random:uniform
 - Function: random:uniform state
     Returns an uniformly distributed inexact real random number in the
     range between 0 and 1.

 - Function: random:exp
 - Function: random:exp state
     Returns an inexact real in an exponential distribution with mean
     1.  For an exponential distribution with mean U use
     `(* U (random:exp))'.

 - Function: random:normal
 - Function: random:normal state
     Returns an inexact real in a normal distribution with mean 0 and
     standard deviation 1.  For a normal distribution with mean M and
     standard deviation D use `(+ M (* D (random:normal)))'.

 - Function: random:normal-vector! vect
 - Function: random:normal-vector! vect state
     Fills VECT with inexact real random numbers which are independent
     and standard normally distributed (i.e., with mean 0 and variance
     1).

 - Function: random:hollow-sphere! vect
 - Function: random:hollow-sphere! vect state
     Fills VECT with inexact real random numbers the sum of whose
     squares is equal to 1.0.  Thinking of VECT as coordinates in space
     of dimension n = `(vector-length VECT)', the coordinates are
     uniformly distributed over the surface of the unit n-shere.

 - Function: random:solid-sphere! vect
 - Function: random:solid-sphere! vect state
     Fills VECT with inexact real random numbers the sum of whose
     squares is less than 1.0.  Thinking of VECT as coordinates in
     space of dimension N = `(vector-length VECT)', the coordinates are
     uniformly distributed within the unit N-shere.  The sum of the
     squares of the numbers is returned.


automatically generated by info2www version 1.2.2.9