jxxcarlson / elm-pseudorandom / PseudoRandom

This module provides two pseudo-random number generators, floatSequence and integerSequence. The first produces a list of n floating point numbers in a specified range. The second produces a list of positive integers in the range 1 to 214748363. A pseudo-random sequence is a sequence of numbers that resembles a random sequence even though it is produced by deterministic means. The notion "resembles" can be made precise using various statistical tests.

Examples:

floatSequence 3 7 (0, 1) |> List.map (roundTo 4) == [0.448,0.0988,0.246]

integerSequence 3 8 == [123092948, 28845728, 98310392]

NOTE: the seed must be a positive integer.

We use the linear congruential generator of (1), Lewis, Goodman, and Miller, for the integerSequence function. For floatSequence we use the triple linear congruential generator of (2).

References:

  1. https://www.math.arizona.edu/~tgk/mc/book_chap3.pdf

  2. http://www.ams.org/journals/mcom/1999-68-225/S0025-5718-99-00996-5/S0025-5718-99-00996-5.pdf

integerSequence : Basics.Int -> Basics.Int -> List Basics.Int

Using the seed, produce a list of n integers k, where 0 <= k < m0.

floatSequence : Basics.Int -> Basics.Int -> ( Basics.Float, Basics.Float ) -> List Basics.Float

Using the seed, produce a list of n floats in the range [a,b)

m0 : Basics.Int

The largest integer that integerSequence will produce is m0 - 1.

roundTo : Basics.Int -> Basics.Float -> Basics.Float

Use this function if all those digits in the output of floatSequence bother you.

roundTo 2 1.2345 == 1.23