add env script
[bpt/guile.git] / module / slib / random.txi
1
2 @defun random n
3
4
5 @defunx random n state
6 Accepts a positive integer or real @var{n} and returns a number of the
7 same type between zero (inclusive) and @var{n} (exclusive). The values
8 returned by @code{random} are uniformly distributed from 0 to @var{n}.
9
10 The optional argument @var{state} must be of the type returned by
11 @code{(seed->random-state)} or @code{(make-random-state)}. It defaults
12 to the value of the variable @code{*random-state*}. This object is used
13 to maintain the state of the pseudo-random-number generator and is
14 altered as a side effect of calls to @code{random}.
15 @end defun
16 @defvar *random-state*
17 Holds a data structure that encodes the internal state of the
18 random-number generator that @code{random} uses by default. The nature
19 of this data structure is implementation-dependent. It may be printed
20 out and successfully read back in, but may or may not function correctly
21 as a random-number state object in another implementation.
22 @end defvar
23
24
25 @defun copy-random-state state
26
27 Returns a new copy of argument @var{state}.
28
29
30 @defunx copy-random-state
31 Returns a new copy of @code{*random-state*}.
32 @end defun
33
34 @defun seed->random-state seed
35
36 Returns a new object of type suitable for use as the value of the
37 variable @code{*random-state*} or as a second argument to @code{random}.
38 The number or string @var{seed} is used to initialize the state. If
39 @code{seed->random-state} is called twice with arguments which are
40 @code{equal?}, then the returned data structures will be @code{equal?}.
41 Calling @code{seed->random-state} with unequal arguments will nearly
42 always return unequal states.
43 @end defun
44
45 @defun make-random-state
46
47
48 @defunx make-random-state obj
49 Returns a new object of type suitable for use as the value of the
50 variable @code{*random-state*} or as a second argument to @code{random}.
51 If the optional argument @var{obj} is given, it should be a printable
52 Scheme object; the first 50 characters of its printed representation
53 will be used as the seed. Otherwise the value of @code{*random-state*}
54 is used as the seed.
55 @end defun