@code{(require 'random)}
@ftindex random




@defun random n state


@defunx random n

@var{n} must be an exact positive integer.  @code{random} returns an exact integer
between zero (inclusive) and @var{n} (exclusive).  The values returned by
@code{random} are uniformly distributed from 0 to @var{n}.

The optional argument @var{state} must be of the type returned by
@code{(seed->random-state)} or @code{(make-random-state)}.  It
defaults to the value of the variable @code{*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 @code{random}.
@end defun

@defvar *random-state*
Holds a data structure that encodes the internal state of the
random-number generator that @code{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.
@end defvar


@defun copy-random-state state

Returns a new copy of argument @var{state}.


@end defun
@defun copy-random-state
Returns a new copy of @code{*random-state*}.
@end defun


@defun seed->random-state seed

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


@defun make-random-state


@defunx make-random-state obj
Returns a new object of type suitable for use as the value of the
variable @code{*random-state*} or as a second argument to @code{random}.
If the optional argument @var{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 @code{*random-state*}
is used as the seed.
@end defun



