NoRedInk / elm-random-pcg-extended / 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 : Random.General.Config Seed

The config for the PCG-extended variant

Getting Started

step : Generator a -> Seed -> ( a, Seed )

initialSeed : Basics.Int -> List Basics.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 =
Random.General.Generator Seed a

bool : Generator Basics.Bool

int : Basics.Int -> Basics.Int -> Generator Basics.Int

float : Basics.Float -> Basics.Float -> Generator Basics.Float

oneIn : Basics.Int -> Generator Basics.Bool

sample : List a -> Generator (Maybe a)

Combining Generators

pair : Generator a -> Generator b -> Generator ( a, b )

list : Basics.Int -> Generator a -> Generator (List a)

maybe : Generator Basics.Bool -> Generator a -> Generator (Maybe a)

choice : a -> a -> Generator a

choices : Generator a -> List (Generator a) -> Generator a

frequency : ( Basics.Float, Generator a ) -> List ( Basics.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

map3 : (a -> b -> c -> d) -> Generator a -> Generator b -> Generator c -> Generator d

map4 : (a -> b -> c -> d -> e) -> Generator a -> Generator b -> Generator c -> Generator d -> Generator e

map5 : (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 -> Basics.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 -> Json.Encode.Value

fromJson : Json.Decode.Decoder Seed

Constants

minInt : Basics.Int

maxInt : Basics.Int