Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the genie Reference Manual, version 1.0.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 13:35:53 2020 GMT+0.
• Introduction | What genie is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
A simple wrapper to generate portably seedable pseudo-random numbers.
Note: This is unmaintained. Please use golden-utils instead.
This library allows you to generate random numbers, with a portable and seedable generator. This means that a generator initialized with a particular seed will yield the same sequence of generated numbers on every Common Lisp implementation.
(ql:quickload :genie)
To generate a random number, you first need to create a generator object seeded with an integer:
(make-generator 123)
Alternatively, you can leave out the seed, to have one generated for you:
(make-generator)
The above will print a log message with the generator's seed value:
[INFO ] [2016-12-07 23:51:29] Random seed: 123258810179538
Once you have a generator, we can use the GEN
function to generate a number. There are a few
different methods to use for generating a number.
To generate a boolean, supply the :BOOL
keyword to GEN
, optionally with a probability for true:
(let ((generator (make-generator)))
(gen :bool generator :probability 0.9))
The above will generate T
90% of the time, and NIL
otherwise.
To generate a number that falls within a range, supply the :RANGE
keyword to GEN
like so:
(let ((generator (make-generator)))
(gen :range generator :min 0.0 :max 1.0))
The above will generate a floating-point number between 0 and 10.
To generate an integer within a range, supply the :INT
keyword to GEN
:
(let ((generator (make-generator)))
(gen :int generator :min 1 :max 100))
The above will generate an integer between 1 and 100, both inclusive. You may also tell it to
generate an odd or an even integer within this range, by using the :PARITYP
keyword as such:
(let ((generator (make-generator)))
(gen :int generator :min 1 :max 100 :parityp t))
This will generate an odd integer between 1 and 100. The value of :MIN
determines the parity of
the result - a value of 2 for :MIN
would generate an even number between 2 and 100.
To choose a random element from a list or other sequence, supply the :ELT
keyword to GEN
:
(let ((generator (make-generator))
(some-sequence '(1 2 3)))
(gen :elt generator :sequence some-sequence))
The above will choose a random element from the sequence given.
Copyright © 2016-2018 Michael Fiano.
Licensed under the MIT License.
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The genie system |
Michael Fiano <mail@michaelfiano.com>
Michael Fiano <mail@michaelfiano.com>
(:git "git@github.com:mfiano/genie.git")
MIT
A simple wrapper to generate portably seedable pseudo-random numbers.
# genie
A simple wrapper to generate portably seedable pseudo-random numbers.
Note: This is unmaintained. Please use [golden-utils](https://github.com/mfiano/golden-utils) instead.
## Overview
This library allows you to generate random numbers, with a portable and seedable generator. This
means that a generator initialized with a particular seed will yield the same sequence of generated
numbers on every Common Lisp implementation.
## Install
“‘ lisp
(ql:quickload :genie)
“‘
## Usage
To generate a random number, you first need to create a generator object seeded with an integer:
“‘ lisp
(make-generator 123)
“‘
Alternatively, you can leave out the seed, to have one generated for you:
“‘ lisp
(make-generator)
“‘
The above will print a log message with the generator’s seed value:
“‘
[INFO ] [2016-12-07 23:51:29] Random seed: 123258810179538
“‘
Once you have a generator, we can use the ‘GEN‘ function to generate a number. There are a few
different methods to use for generating a number.
### Generate a boolean value (T or NIL)
To generate a boolean, supply the ‘:BOOL‘ keyword to ‘GEN‘, optionally with a probability for true:
“‘ lisp
(let ((generator (make-generator)))
(gen :bool generator :probability 0.9))
“‘
The above will generate ‘T‘ 90% of the time, and ‘NIL‘ otherwise.
### Generate a floating-point number within a range
To generate a number that falls within a range, supply the ‘:RANGE‘ keyword to ‘GEN‘ like so:
“‘ lisp
(let ((generator (make-generator)))
(gen :range generator :min 0.0 :max 1.0))
“‘
The above will generate a floating-point number between 0 and 10.
### Generate an integer
To generate an integer within a range, supply the ‘:INT‘ keyword to ‘GEN‘:
“‘ lisp
(let ((generator (make-generator)))
(gen :int generator :min 1 :max 100))
“‘
The above will generate an integer between 1 and 100, both inclusive. You may also tell it to
generate an odd or an even integer within this range, by using the ‘:PARITYP‘ keyword as such:
“‘ lisp
(let ((generator (make-generator)))
(gen :int generator :min 1 :max 100 :parityp t))
“‘
This will generate an odd integer between 1 and 100. The value of ‘:MIN‘ determines the parity of
the result - a value of 2 for ‘:MIN‘ would generate an even number between 2 and 100.
### Choose a random element from a sequence
To choose a random element from a list or other sequence, supply the ‘:ELT‘ keyword to ‘GEN‘:
“‘ lisp
(let ((generator (make-generator))
(some-sequence ’(1 2 3)))
(gen :elt generator :sequence some-sequence))
“‘
The above will choose a random element from the sequence given.
## License
Copyright © 2016-2018 [Michael Fiano](mailto:mail@michaelfiano.com).
Licensed under the MIT License.
1.0.0
genie.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The genie.asd file | ||
• The genie/package.lisp file | ||
• The genie/genie.lisp file |
Next: The genie/package․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
/home/quickref/quicklisp/dists/quicklisp/software/genie-20190307-git/genie.asd
genie (system)
Next: The genie/genie․lisp file, Previous: The genie․asd file, Up: Lisp files [Contents][Index]
Previous: The genie/package․lisp file, Up: Lisp files [Contents][Index]
package.lisp (file)
genie (system)
genie.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The genie package |
package.lisp (file)
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions |
Previous: Definitions, Up: Definitions [Contents][Index]
• Exported functions | ||
• Exported generic functions |
Next: Exported generic functions, Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Create a random number generator object, using SEED to initialize it. If SEED is not supplied, a new seed will be generated.
genie.lisp (file)
Compute a seed to be given to a generator.
genie.lisp (file)
Previous: Exported functions, Up: Exported definitions [Contents][Index]
Generate a random number of a certain kind.
genie.lisp (file)
Randomly select an element from SEQUENCE.
Generate an integer between MIN and MAX (inclusive). If PARITYP is non-nil, generate an even number if MIN is even, or an odd number if MIN is odd.
Generate a number between MIN and MAX.
Generate a true or false value, with the given PROBABILITY for true.
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | F G L |
---|
Jump to: | F G L |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | F G M |
---|
Jump to: | F G M |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | G P S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
G | |||
genie : | The genie system | ||
genie : | The genie package | ||
| |||
P | |||
Package, genie : | The genie package | ||
| |||
S | |||
System, genie : | The genie system | ||
|
Jump to: | G P S |
---|