Sources of Random Bits
This is a Chicken implementation of SRFI-27. This document only describes the extensions and violations. For the SRFI-27 API see SRFI-27.
make-entropy-source | (-> %entropy-source) |
entropy-source? | (object -> boolean) |
entropy-source | (-> %entropy-source) |
entropy-kind | (-> (or string symbol)) |
entropic-u8vector | ((fixnum positive) #!optional u8vector -> u8vector) |
entropic-f64vector | ((fixnum positive) #!optional f64vector -> f64vector) |
entropic-u8 | (-> (fixnum (<= 0 _1 255))) |
entropic-f64 | (-> (flonum (not negative))) |
random-integer | ((integer exact positive) -> (integer exact (not negative) (< _ _1))) |
random-real | (-> (real inexact (< 0.0 _ 1.0))) |
default-random-source | %random-source |
make-random-source | (-> %random-source) |
random-source? | (object -> boolean) |
random-source-kind | (%random-source -> (or string symbol)) |
random-source-log2-period | (%random-source -> (fixnum positive)) |
random-source-maximum-modulus | (%random-source -> (integer positive)) |
random-source-maximum-range | (%random-source -> (integer positive)) |
random-source-state-ref | (%random-source -> random-state) |
random-source-state-set! | (%random-source random-state -> unspecified) |
random-source-randomize! | (%random-source -> unspecified) |
random-source-randomize!/entropy | (%random-source (or entropy-structure %entropy-source) -> unspecified) |
random-source-pseudo-randomize! | (%random-source (integer exact positive) (integer exact positive) -> unspecified) |
random-source-make-integers | (%random-source -> ((integer exact positive) -> (integer exact (not negative) (< _ _1)))) |
random-source-make-reals | (%random-source #!optional (real inexact (< 0.0 _ 1.0)) -> (-> (real inexact (< 0.0 _ 1.0)))) |
All random number generators are randomized using the current entropy source. See current-entropy-source-structure
below.
To use a random structure do the following: (require-extension lexmod srfi-27) (lexmod-open RANDOM-SOURCE-STRUCTURE)
, where RANDOM-SOURCE-STRUCTURE is one of the structures below.
Pierre L'Ecuyer's Multiple Recursive Generator 32k3a.
George Marsaglia's Multiply With Carry generator.
George Marsaglia's "Mother of All" generator.
Returns a random source structure for RANDOM-SOURCE-MAKE-PROCEDURE. Not automatically registered. See register-random-source-structure!
below.
Returns a list of the known random source structures.
Is OBJECT a random source structure?
Assuming OBJECT is a random source structure register it as a known source.
The procedure COMBINE-RANDOM-INTEGERS takes a list of the random integers generated by the combined random sources and the limit. It must return a combined random integer within the limit.
The procedure COMBINE-RANDOM-REALS takes a list of the random reals generated by the combined random sources and an optional unit. It must return a combined random real with unit dispersion.
Returns a new random-source
. Provides a default for the COMBINE-RANDOM-INTEGERS (sum mod limit) and COMBINE-RANDOM-REALS (product) when not supplied.
Returns a new random-source
.
Entropy from (current-seconds)
.
Entropy from /dev/random
.
Entropy from /dev/urandom
.
Entropy from CryptGenRandom
.
User defined entropy structures are not automatically registered. See register-entropy-source-structure!
below.
Returns an entropy source structure for the entropy source created by ENTROPY-SOURCE-MAKE-PROCEDURE.
Returns an entropy source using the contents of the file at PATHNAME. KIND is a name for the entropy source, the PATHNAME is used if not supplied.
Automatically closed after timeout and re-opened on need.
Returns an entropy source structure.
Returns an entropy source using the INPUT-PORT. KIND is a name for the entropy source, a (gensym)
is used if not supplied.
The INPUT-PORT must be explicitly closed.
Returns an entropy source structure.
Returns an entropy source using the F64PROCEDURE, and, optionally, the U8PROCEDURE. The procedures must generate a value of the specified type on each invocation. KIND is a name for the entropy source, a (gensym)
is used if not supplied.
Returns an entropy source structure.
Is OBJECT an entropy source structure?
Returns a list of the known entropy source structures.
Assuming OBJECT is an entropy source structure register it as a known source.
Returns or sets the current entropy source structure.
The ENTROPY-SOURCE-STRUCTURE is automatically "opened"!
Returns or sets the current random source structure.
The RANDOM-SOURCE-STRUCTURE is automatically "opened"!
Returns or sets the current number of seconds to wait before automatically closing an open port.
All distributions return 2 values. The first is a procedure of arity 0, the random distribution generator. The second is a procedure of arity 0, returning the configuration arguments as multiple-values, in the order they appear in the make-*
argument list. The report procedure can be safely ignored.
Returns an integer random number generator.
SOURCE | A %random-source or a random-source-structure. Default is the 'current-random-source-structure'. |
HIGH | An integer or boolean. The largest desired random integer. Default is one less then maximum range for the source. When boolean the default is used. |
LOW | An integer. The smallest desired random integer. Default is 0. |
UNIT | An integer. The spacing between desired random integers. Default is 1. |
Returns a real random number generator.
SOURCE | A %random-source or a random-source-structure. Default is the 'current-random-source-structure'. |
UNIT | A number in (0.0 1.0) or boolean. The spacing between the reals. Default is machine epsilon. When boolean the default is used. |
Exponentially distributed random inexact reals.
Normal distributed random inexact reals.
Triangluar distributed random inexact reals.
Poisson distributed random inexact reals.
Bernoulli distributed random booleans.
Binomial distributed random integers.
Geometric distributed random inexact reals.
Log normal distributed random inexact reals.
Cauchy distributed random inexact reals.
Gamma distributed random inexact reals.
Erlang distributed random inexact reals.
Pareto distributed random inexact reals.
Levy distributed random inexact reals.
Fills the VECTOR with normal distributed real numbers. When just a random generator is specified it is assumed to be a source of random normals!
VECTOR | A vector or 64vector. |
RAND | A random reals source. Default is 'make-uniform-random-reals'. |
MEAN | A number. |
STDDEV | A number. |
Fills the VECTOR with inexact reals the sum of whose squares is equal to 1.0. When just a random generator is specified it is assumed to be a source of random normals!
VECTOR | A vector or 64vector. |
RAND | A random reals source. Default is 'make-uniform-random-reals'. |
MEAN | A number. |
STDDEV | A number. |
Fills the VECTOR with inexact reals the sum of whose squares is less than 1.0. When just a random generator is specified it is assumed to be a source of random normals!
VECTOR | A vector or 64vector. |
RAND | A random reals source. Default is 'make-uniform-random-reals'. |
MEAN | A number. |
STDDEV | A number. |
These are only of interest if implementing an entropy or random source.
kind | Description of the entropy source. symbol or string |
u8 | Procedure to generate an entropic unsigned 8 bit integer. (-> (fixnum (<= 0 _1 255))) |
f64 | Procedure to generate an entropic 64 bit floating-point. (-> (flonum (not negative))) |
u8vector | Procedure to generate a vector of entropic unsigned 8 bit integer. ((fixnum postive) #!optional (u8vector (<= (u8vector-length _2) _1)) -> u8vector) |
f64vector | Procedure to generate a vector of entropic 64 bit floating-point. ((fixnum postive) #!optional (f64vector (<= (f64vector-length _2) _1)) -> f64vector) |
Is OBJECT an %entropy-source?
Returns the u8 procedure.
Returns the f64 procedure.
Returns the u8vector procedure.
Returns the f64vector procedure.
kind | The identifier for the random source. symbol or string |
log2-period | Period of the random source as a power of 2. fixnum |
maximum-range | Maximum range. integer |
maximum-modulus | Maximum modulus. integer |
state-ref | Procedure to return the random state. (-> random-state) |
state-set! | Procedure to set the random state. (random-state -> unspecified) |
randomize! | Procedure to randomize the current state. (entropy-source -> unspecified) |
pseudo-randomize! | Procedure to randomize current state for substreams. ((integer exact positive) (integer exact positive) -> unspecified) |
make-integers | Procedure to return a random integer stream generator. (-> ((integer exact positive) -> (integer exact (not negative) (< _ _1)))) |
make-reals | Procedure to return a random inexact stream generator. (#!optional (real inexact (< 0.0 _1 1.0)) -> (-> (real inexact (< 0.0 _ 1.0)))) |
Is OBJECT a %random-source?
Returns the kind.
Returns the period base 2 exponent.
Returns the maximum range.
Returns the maximum modulus.
Returns the state-ref procedure.
Returns the state-set! procedure.
Returns the randomize! procedure.
Returns the pseudo-randomize! procedure.
Returns the make-integers procedure.
Returns the make-reals procedure.
Returns an u8vector seeded from ENTROPY-SOURCE.
Returns an f64vector seeded from ENTROPY-SOURCE.
Returns an u8 from the F64PROCEDURE.
Returns an u8vector seeded from the U8PROCEDURE.
Returns an u8vector seeded from the F64PROCEDURE.
Returns an f64vector seeded from the F64PROCEDURE.
Returns an u8 from the INPUT-PORT.
Returns an f64 from the INPUT-PORT.
Returns an u8vector seeded from the INPUT-PORT.
Returns an f64vector seeded from the F64PROCEDURE. The
procedure is invoked as (F64PROCEDURE INPUT-PORT)
.
Returns an entropy source.
Poor documentation. Usually just procedure signature.
No good examples.
The semi-generic nature of the random structure in the specification is odd. A random-structure must be created for every generator, but, except for 'make-random-source', the exported procedures will function with any %random-source.
The entropy structure is opposite of the random structure, mostly specific. Subject to future revision.
; Please see "conf-test.scm" in this egg.
Copyright (c) 2006-2007, Kon Lovett. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Does not supercede any restrictions found in the source code.