Random Number Generators (RNG)
This library provides an RNG type (Random Number Generator) for
Tomo. This type represents a self-contained
piece of data that encapsulates the state of a relatively fast and relatively
secure pseudo-random number generator. The current implementation is based on
the ChaCha20 stream
cipher, inspired by
arc4random in OpenBSD.
An RNG object can be used for deterministic, repeatable generation of
pseudorandom numbers (for example, to be used in a video game for creating
seeded levels). The default random number generator for Tomo is called random
and is, by default, initialized with random data from the operating system when
a Tomo program launches.
RNG Functions
This documentation provides details on RNG functions available in the API.
Lists also have some methods which use RNG values:
list.shuffle(), list.shuffled(), list.random(), and list.sample().
func bool(rng: RandomNumberGenerator, p: Num = 0.5 -> Bool)func byte(rng: RandomNumberGenerator -> Byte)func bytes(rng: RandomNumberGenerator, count: Int -> [Byte])func int(rng: RandomNumberGenerator, min: Int, max: Int -> Int)func new(seed: [Byte] = (/dev/urandom).read_bytes(40)! -> RandomNumberGenerator)func num(rng: RandomNumberGenerator, min: Num = 0.0, max: Num = 1.0 -> Num)
Usage
Put this in your modules.ini:
1 [random]2 version=v1.23 git=https://github.com/bruce-hill/tomo-random