Module Random.Array

Random functions for arrays.

val shuffle : ?state:State.t -> 'a array -> unit

(shuffle ?state a) performs a destructive in-place Fisher–Yates shuffle on the array a; O(n).

val sample_with : ?state:State.t -> int -> 'a array -> 'a list

(sample_with ?state n a) returns a random sample, with replacement, of size n of the array a; tail-recursive, O(n).

  • raises Invalid_argument

    if a is empty

val sample_without : ?state:State.t -> int -> 'a array -> 'a list

(sample_without ?state n a) returns a random sample, without replacement, of size n of the array a; tail-recursive, O(n).

  • raises Invalid_argument

    if a is empty or if n > Array.length a