Documentation
¶
Overview ¶
Package random is the generator of the format and its places of randomness, written from the constants of the format's text rather than taken from math/rand/v2, with an error on an argument outside a function's domain. Nothing outside module-kit imports it: what goes out is the instance of an attempt, from package template.
A Stream gives numbers through the five functions the vectors of the generator check, and through nothing else: no shuffle of a list, which module-kit does not do. The generator keeps no state of its own: a stream lives in the one call that builds it. math/rand/v2 and hash/fnv are the reference in its tests alone, and no randomness comes from anything but a seed.
Index ¶
Constants ¶
const MaxPermutation = math.MaxInt32
MaxPermutation is the greatest count that Permutation orders.
Variables ¶
var ErrDomain = errors.New("outside the domain")
ErrDomain is what a function gives on an argument outside its domain, and a place on a name that is none: the function draws no integer, and no place is built.
Functions ¶
func Words ¶
Words gives the two words that start the stream of a place of randomness: the high one FNV-1a of 64 bits of the UTF-8 text of the seed in decimal digits and then, for each name in order, | and the name; the low one the seed itself. A place has a name at least, and a name is UTF-8 that is not empty and holds no |; names compare as written, with no normalization. Any other list of names gives ErrDomain.
Types ¶
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is the generator, PCG with 128 bits of state, its state the number high · 2^64 + low. Each of its five functions draws as many integers as the format's text says. A Stream is not for two goroutines at once: each use builds its own, and lives in one call.
func Place ¶
Place gives the stream of the place of randomness of a seed and its names, as Words starts it.
func (*Stream) Below ¶
Below gives an integer from 0 to b − 1, for a bound b from 1 to 2^64 − 1. A bound that is a power of two masks the next integer, which draws one; any other takes the high word of the product of the next integer and b, by Lemire's method, and takes the product again with the next integer while its low word is less than (2^64 − b) mod b, each product drawing one.
func (*Stream) Between ¶
Between gives a + below(c − a + 1), an integer from a to c, both included, for signed integers a ≤ c with c − a + 1 at most 2^63 − 1. a ≤ c is checked first, so that c − a, taken in the words of 64 bits that wrap, is the count less one and overflows nothing.
func (*Stream) Fraction ¶
Fraction gives a number from 0 up to 1, never 1: the low 53 bits of the next integer, divided by 2^53, which a double holds exactly. It draws one integer.