jxxcarlson/elm-pseudorandom/1.0.0

NOTE: the latest version is 1.0.3

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 m0 = 214748364. 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 generator 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 : Int -> Int -> List Int

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

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

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

m0 : Int

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

roundTo : Int -> Float -> Float

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

roundTo 2 1.2345 == 1.23