-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout.html
More file actions
executable file
·145 lines (121 loc) · 16 KB
/
about.html
File metadata and controls
executable file
·145 lines (121 loc) · 16 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>Random-State</title> <meta name="viewport" content="width=device-width"> <meta name="description" content="Portable random number generation."> <meta name="author" content="Nicolas Hafner <shinmera@tymoon.eu>"> <style type="text/css"> body{
max-width: 1024px;
margin: 0 auto 0 auto;
font-family: sans-serif;
color: #333333;
font-size: 14pt;
padding: 5px;
}
body>header{
display:flex;
align-items: center;
justify-content: center;
flex-direction: column;
max-width: 100%;
text-align: center;
}
body>header img{
max-width: 50%;
}
img{
max-width: 100%;
max-height: 100%;
}
code{
font-family: Consolas, Inconsolata, monospace;
}
a{
text-decoration: none;
color: #0055AA;
}
a img{
border: none;
}
#documentation{
text-align: justify;
}
#documentation pre{
margin-left: 20px;
overflow: auto;
}
#documentation img{
margin: 5px;
}
#symbol-index>ul{
list-style: none;
padding: 0;
}
#symbol-index .package>ul{
list-style: none;
padding: 0 0 0 10px;
}
#symbol-index .package .nicknames{
font-weight: normal;
}
#symbol-index .package h4{
display: inline-block;
margin: 0;
}
#symbol-index .package article{
margin: 0 0 15px 0;
}
#symbol-index .package article header{
font-size: 1.2em;
font-weight: normal;
}
#symbol-index .package .name{
margin-right: 5px;
}
#symbol-index .package .docstring{
margin: 0 0 0 15px;
white-space: pre-wrap;
font-size: 12pt;
}
@media (max-width: 800px){
body{font-size: 12pt;}
} </style> </head> <body> <header> <h1>random-state</h1> <span class="version">0.1.0</span> <p class="description">Portable random number generation.</p> </header> <main> <article id="documentation"> <div><h2 id="about_random-state">About random-state</h2> <p>This is a collection of pseudo random number generators (PRNGs). While Common Lisp does provide a <code><a href="http://l1sp.org/cl/random">RANDOM</a></code> function, it does not allow the user to pass an explicit SEED, nor to portably exchange the random state between implementations. This can be a headache in cases like games, where a controlled seeding process can be very useful.</p> <h2 id="how_to">How To</h2> <p>For both curiosity and convenience, this library offers multiple algorithms to generate random numbers, as well as a bunch of generally useful methods to produce desired ranges.</p> <pre><code>(<a href="http://l1sp.org/cl/loop">loop</a> with generator = (<a href="#RANDOM-STATE:MAKE-GENERATOR">random-state:make-generator</a> :mersenne-twister-32 123)
repeat 10
collect (<a href="#RANDOM-STATE:RANDOM-INT">random-state:random-int</a> generator 0 10))
=> (5 6 6 3 2 8 6 9 6 1)
</code></pre> <p>The library does make some efforts to be reasonably efficient while preserving usability, but each of the implementations could be optimised further. For performance critical sections, you might want to take matters into your own hands and only rely on <code><a href="#RANDOM-STATE:RANDOM-BYTE">random-byte</a></code> for the most direct access to the generator. If that still is not sufficiently fast, creating a tailored implementation of an algorithm based on the source code of this library should not be difficult.</p> <p>Several methods to compute random numbers in certain ranges are provided in advance: <code><a href="#RANDOM-STATE:RANDOM-BYTE">random-byte</a></code>, <code><a href="#RANDOM-STATE:RANDOM-BYTES">random-bytes</a></code>, <code><a href="#RANDOM-STATE:RANDOM-UNIT">random-unit</a></code>, <code><a href="#RANDOM-STATE:RANDOM-FLOAT">random-float</a></code>, and <code><a href="#RANDOM-STATE:RANDOM-INT">random-int</a></code>. Each of those can also be used with just the name of the generator you'd like to use as the first argument, in which case a global instance will be used.</p> </div> </article> <article id="copyright"> <h2>Copyright</h2> <span>random-state</span> is licensed under the <span><a href="https://tldrlegal.com/search?q=Artistic">Artistic</a></span> license. © <span>Nicolas Hafner <shinmera@tymoon.eu></span> . This library can be obtained on <a href="https://github.com/Shinmera/random-state">https://github.com/Shinmera/random-state</a>. </article> <article id="symbol-index"> <h2>Package Index</h2> <ul><li class="package"> <h3> <a name="RANDOM-STATE" href="#RANDOM-STATE">RANDOM-STATE</a> <span class="nicknames">(ORG.SHIRAKUMO.RANDOM-STATE)</span> </h3> <ul><li> <a name="RANDOM-STATE:GENERATOR"> </a> <article id="CLASS RANDOM-STATE:GENERATOR"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3AGENERATOR">GENERATOR</a></code></h4> </header> <div class="docstring"><pre>General class for any random number generator.
See <a href="#RANDOM-STATE:SEED">SEED</a>
See <a href="#RANDOM-STATE:BYTES">BYTES</a>
See <a href="#RANDOM-STATE:MAKE-GENERATOR">MAKE-GENERATOR</a>
See <a href="#RANDOM-STATE:RANDOM-BYTE">RANDOM-BYTE</a>
See <a href="#RANDOM-STATE:RANDOM-BYTES">RANDOM-BYTES</a>
See <a href="#RANDOM-STATE:RANDOM-UNIT">RANDOM-UNIT</a>
See <a href="#RANDOM-STATE:RANDOM-FLOAT">RANDOM-FLOAT</a>
See <a href="#RANDOM-STATE:RANDOM-INT">RANDOM-INT</a>
See <a href="#RANDOM-STATE:RESEED">RESEED</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:LINEAR-CONGRUENCE"> </a> <article id="CLASS RANDOM-STATE:LINEAR-CONGRUENCE"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3ALINEAR-CONGRUENCE">LINEAR-CONGRUENCE</a></code></h4> </header> <div class="docstring"><pre>A very simple random number generator based on linear congruence.
See <a href="NIL">https://en.wikipedia.org/wiki/Linear_congruential_generator</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:MERSENNE-TWISTER-32"> </a> <article id="CLASS RANDOM-STATE:MERSENNE-TWISTER-32"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3AMERSENNE-TWISTER-32">MERSENNE-TWISTER-32</a></code></h4> </header> <div class="docstring"><pre>The de-facto standard random number generator algorithm.
See <a href="NIL">https://en.wikipedia.org/wiki/Mersenne_Twister</a>
See <a href="NIL">http://www.acclab.helsinki.fi/~knordlun/mc/mt19937.c</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:MERSENNE-TWISTER-64"> </a> <article id="CLASS RANDOM-STATE:MERSENNE-TWISTER-64"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3AMERSENNE-TWISTER-64">MERSENNE-TWISTER-64</a></code></h4> </header> <div class="docstring"><pre>A 64 bit variant of the Mersenne Twister algorithm.
See <a href="#RANDOM-STATE:MERSENNE-TWISTER-32">MERSENNE-TWISTER-32</a>
See <a href="NIL">http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:MIDDLE-SQUARE"> </a> <article id="CLASS RANDOM-STATE:MIDDLE-SQUARE"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3AMIDDLE-SQUARE">MIDDLE-SQUARE</a></code></h4> </header> <div class="docstring"><pre>An incredibly primitive, and basically in practise useless, random number algorithm.
See <a href="NIL">https://en.wikipedia.org/wiki/Middle-square_method</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:PCG"> </a> <article id="CLASS RANDOM-STATE:PCG"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3APCG">PCG</a></code></h4> </header> <div class="docstring"><pre>An adaptation of the PCG rng.
See <a href="NIL">http://www.pcg-random.org</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RC4"> </a> <article id="CLASS RANDOM-STATE:RC4"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3ARC4">RC4</a></code></h4> </header> <div class="docstring"><pre>The RC4 cryptographic random number generator.
See <a href="NIL">https://en.wikipedia.org/wiki/RC4</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:TT800"> </a> <article id="CLASS RANDOM-STATE:TT800"> <header class="class"> <span class="type">class</span> <h4 class="name"><code><a href="#CLASS%20RANDOM-STATE%3ATT800">TT800</a></code></h4> </header> <div class="docstring"><pre>The predecessor to the Mersenne Twister algorithm.
See <a href="NIL">http://random.mat.sbg.ac.at/publics/ftp/pub/data/tt800.c</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:GENERATOR-CLASS"> </a> <article id="FUNCTION RANDOM-STATE:GENERATOR-CLASS"> <header class="function"> <span class="type">function</span> <code>(</code><h4 class="name"><code><a href="#FUNCTION%20RANDOM-STATE%3AGENERATOR-CLASS">GENERATOR-CLASS</a></code></h4> <code class="qualifiers"></code> <code class="arguments">NAME</code><code>)</code> </header> <div class="docstring"><pre>Attempts to find the named generator class. Accepts strings, symbols, and classes.
If no generator can be found, an error is signalled.</pre></div> </article> </li><li> <a name="RANDOM-STATE:GLOBAL-GENERATOR"> </a> <article id="FUNCTION RANDOM-STATE:GLOBAL-GENERATOR"> <header class="function"> <span class="type">function</span> <code>(</code><h4 class="name"><code><a href="#FUNCTION%20RANDOM-STATE%3AGLOBAL-GENERATOR">GLOBAL-GENERATOR</a></code></h4> <code class="qualifiers"></code> <code class="arguments">NAME</code><code>)</code> </header> <div class="docstring"><pre>Returns a global instance of a generator.
See <a href="#RANDOM-STATE:MAKE-GENERATOR">MAKE-GENERATOR</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:HOPEFULLY-SUFFICIENTLY-RANDOM-SEED"> </a> <article id="FUNCTION RANDOM-STATE:HOPEFULLY-SUFFICIENTLY-RANDOM-SEED"> <header class="function"> <span class="type">function</span> <code>(</code><h4 class="name"><code><a href="#FUNCTION%20RANDOM-STATE%3AHOPEFULLY-SUFFICIENTLY-RANDOM-SEED">HOPEFULLY-SUFFICIENTLY-RANDOM-SEED</a></code></h4> <code class="qualifiers"></code> <code class="arguments"></code><code>)</code> </header> <div class="docstring"><pre>Attempts to find a sufficiently random seed.
On Unix, this reads 64 bits from /dev/urandom
On Windows+SBCL, this reads 64 bits from SB-WIN32:CRYPT-GEN-RANDOM
Otherwise it uses an XOR of GET-INTERNAL-REAL-TIME and GET-UNIVERSAL-TIME.</pre></div> </article> </li><li> <a name="RANDOM-STATE:MAKE-GENERATOR"> </a> <article id="FUNCTION RANDOM-STATE:MAKE-GENERATOR"> <header class="function"> <span class="type">function</span> <code>(</code><h4 class="name"><code><a href="#FUNCTION%20RANDOM-STATE%3AMAKE-GENERATOR">MAKE-GENERATOR</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR &OPTIONAL SEED &REST INITARGS</code><code>)</code> </header> <div class="docstring"><pre>Creates a generator of the given type.
The GENERATOR can be any name supported by GENERATOR-CLASS.
After construction, RESEED is called on the generator with the given SEED.
See <a href="#RANDOM-STATE:GENERATOR-CLASS">GENERATOR-CLASS</a>
See <a href="#RANDOM-STATE:RESEED">RESEED</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:BYTES"> </a> <article id="GENERIC RANDOM-STATE:BYTES"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ABYTES">BYTES</a></code></h4> <code class="qualifiers"></code> <code class="arguments">OBJECT</code><code>)</code> </header> <div class="docstring"><pre>Returns the number of bytes (bits) that a RANDOM-BYTE call of this generator produces.</pre></div> </article> </li><li> <a name="RANDOM-STATE:RANDOM-BYTE"> </a> <article id="GENERIC RANDOM-STATE:RANDOM-BYTE"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARANDOM-BYTE">RANDOM-BYTE</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR</code><code>)</code> </header> <div class="docstring"><pre>Returns an integer of fresh random output from the generator.
The integer is at most 2^(BYTES GENERATOR)-1 and at least 0.
See <a href="#RANDOM-STATE:GENERATOR">GENERATOR</a>
See <a href="#RANDOM-STATE:BYTES">BYTES</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RANDOM-BYTES"> </a> <article id="GENERIC RANDOM-STATE:RANDOM-BYTES"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARANDOM-BYTES">RANDOM-BYTES</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR BYTES</code><code>)</code> </header> <div class="docstring"><pre>Returns an integer of fresh random output from the generator.
The integer is at most 2^(BYTES)-1 and at least 0.
See <a href="#RANDOM-STATE:GENERATOR">GENERATOR</a>
See <a href="#RANDOM-STATE:RANDOM-BYTE">RANDOM-BYTE</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RANDOM-FLOAT"> </a> <article id="GENERIC RANDOM-STATE:RANDOM-FLOAT"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARANDOM-FLOAT">RANDOM-FLOAT</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR FROM TO</code><code>)</code> </header> <div class="docstring"><pre>Returns a float of fresh random output from the generator.
The returned value is a double-float between FROM and TO.
See <a href="#RANDOM-STATE:GENERATOR">GENERATOR</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RANDOM-INT"> </a> <article id="GENERIC RANDOM-STATE:RANDOM-INT"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARANDOM-INT">RANDOM-INT</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR FROM TO</code><code>)</code> </header> <div class="docstring"><pre>Returns an integer of fresh random output from the generator.
The returned value is an integer between FROM and TO.
See <a href="#RANDOM-STATE:GENERATOR">GENERATOR</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RANDOM-UNIT"> </a> <article id="GENERIC RANDOM-STATE:RANDOM-UNIT"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARANDOM-UNIT">RANDOM-UNIT</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR</code><code>)</code> </header> <div class="docstring"><pre>Returns a unit float of fresh random output from the generator.
The returned value is a double-float between 0.0 and 1.0.
See <a href="#RANDOM-STATE:GENERATOR">GENERATOR</a></pre></div> </article> </li><li> <a name="RANDOM-STATE:RESEED"> </a> <article id="GENERIC RANDOM-STATE:RESEED"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ARESEED">RESEED</a></code></h4> <code class="qualifiers"></code> <code class="arguments">GENERATOR &OPTIONAL NEW-SEED</code><code>)</code> </header> <div class="docstring"><pre>Reinitialises the generator with the new seed.
The seed should be an integer. If not given, the current value returned by
HOPEFULLY-SUFFICIENTLY-RANDOM-SEED is used.</pre></div> </article> </li><li> <a name="RANDOM-STATE:SEED"> </a> <article id="GENERIC RANDOM-STATE:SEED"> <header class="generic"> <span class="type">generic</span> <code>(</code><h4 class="name"><code><a href="#GENERIC%20RANDOM-STATE%3ASEED">SEED</a></code></h4> <code class="qualifiers"></code> <code class="arguments">OBJECT</code><code>)</code> </header> <div class="docstring"><pre>Returns the seed that was used to initialise the generator.</pre></div> </article> </li></ul> </li></ul> </article> </main> </body> </html>