NoRedInk/elm-random-extra/2.1.1

NOTE: this package is not compatible with Elm 0.19.1

Random.Array

List of Array Generators

Generate an Array

array : Int -> Generator a -> Generator (Array a)

Generate a random array of given size given a random generator

randomLength5IntArray = array 5 (int 0 100)
emptyArray : Generator (Array a)

Generator that always generates the empty array

rangeLengthArray : Int -> Int -> Generator a -> Generator (Array a)

Generate a random array of random length given a minimum length and a maximum length.

Random Operations on an Array

sample : Array a -> Generator (Maybe a)

Sample with replacement: produce a randomly selected element of the array, or Nothing for an empty array. Takes O(1) time.

choose : Array a -> Generator ( Maybe a, Array a )

Sample without replacement: produce a randomly selected element of the array, and the array with that element omitted (shifting all later elements down).

shuffle : Array a -> Generator (Array a)

Shuffle the array using the Fisher-Yates algorithm. Takes O(n log n) time and O(n) additional space.