blob: d9474f9b42bca0e2a31bfd109a7c36e31891f18a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
@defun random n
@defunx random n state
Accepts a positive integer or real @var{n} and returns a number of the
same type 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}.
@defunx 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
|