NoRedInk/elm-random-pcg-extended/1.0.0

Random.Pcg.Extended

This is an extended version of the Pcg random generator. It offers k dimensional equidistributed random numbers.

It has a larger space cost than the normal Pcg version, but it also offers a much higher period

config : Config Seed

The config for the PCG-extended variant

Getting Started

step : Generator a -> Seed -> ( a, Seed )
initialSeed : Int -> List Int -> Seed

Seed this generator with some random data. Best get this via a flag from window.crypto.getRandomValues(..).

The more random integers you provide, the longer the period gets.

This is based on section 7.1 from the PCG paper Since the PCG generator used as a base is the RXS-M-XS variant (section 6.3.4), The extended generator will have a period of 2^((List.length extendedSeed + 1)*32)

If your extendedSeed list has a length that is a power of two, the performance will be a bit better.

Basic Generators

type alias Generator a =
Generator Seed a
bool : Generator Bool
int : Int -> Int -> Generator Int
float : Float -> Float -> Generator Float
oneIn : Int -> Generator Bool
sample : List a -> Generator (Maybe a)

Combining Generators

pair : Generator a -> Generator b -> Generator ( a, b )
list : Int -> Generator a -> Generator (List a)
maybe : Generator Bool -> Generator a -> Generator (Maybe a)
choice : a -> a -> Generator a
choices : Generator a -> List (Generator a) -> Generator a
( Float, Generator a )
-> List ( Float, Generator a )
-> Generator a

Custom Generators

constant : a -> Generator a
map : (a -> b) -> Generator a -> Generator b
map2 : (a -> b -> c) -> Generator a -> Generator b -> Generator c
(a -> b -> c -> d)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
(a -> b -> c -> d -> e)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
(a -> b -> c -> d -> e -> f)
-> Generator a
-> Generator b
-> Generator c
-> Generator d
-> Generator e
-> Generator f
andMap : Generator a -> Generator (a -> b) -> Generator b
andThen : (a -> Generator b) -> Generator a -> Generator b
filter : (a -> Bool) -> Generator a -> Generator a

Working With Seeds

type Seed
independentSeed : Generator Seed

This gives you an independant seed.

TODO: how sound is this function?

toJson : Seed -> Value
fromJson : Decoder Seed

Constants

minInt : Int
maxInt : Int