gleam_stats/generators

A module for generating random numbers. Several different Pseudo-Random Number Generator (PRNG) algorithms are implemented by this module. Each function listed in the following creates a base-iterator that yields pseudo-random integer numbers. A base-iterator created by one of the functions can then used with other functions to generate random numbers from common distributions. See the ‘gleam_stats/rand’ module for this functionality.


Functions

pub fn seed_lcg32(seed: Int) -> Iterator(Int)

Create a base-iterator that uses the Linear Congruential Generator (LCG32) algorithm to generate random numbers. The LCG32 algorithm is a generator of 32-bit random numbers and uses a 32-bit integer seed.

Example:
 import gleam/iterator.{Iterator}
 import gleam_stats/generators

 pub fn example () {
   let seed: Int = 5
   let stream: Iterator(Int) = generators.seed_lcg32(seed)
 }
pub fn seed_mt19937(seed: Int) -> Iterator(Int)

Create a base-iterator that uses the Mersenne Twister (MT19937) algorithm to generate random numbers. The MT19937 algorithm is a generator of 32-bit random numbers and uses a 32-bit integer seed.

Example:
 import gleam/iterator.{Iterator}
 import gleam_stats/generators

 pub fn example () {
   let seed: Int = 5
   let stream: Iterator(Int) = generators.seed_mt19937(seed)
 }
pub fn seed_pcg32(seed: Int, seq: Int) -> Iterator(Int)

Create a base-iterator that uses the Permuted Congruential Generator (PCG32) algorithm to generate random numbers. The PCG32 algorithm is a generator of 32-bit random numbers and uses two 64-bit integer seeds (internal initial state and sequence/stream number).

Example:
 import gleam/iterator.{Iterator}
 import gleam_stats/generators

 pub fn example () {
   let seed: Int = 5
   let seed_sequence: Int = 5
   let stream: Iterator(Int) = generators.seed_pcg32(seed, seed_sequence)
 }