shuffle

Shuffles the elements of array in-place.

  1. T[] shuffle(T[] array, double rand)
    T[]
    shuffle
    (
    T
    )
    (
    T[] array
    ,
    lazy double rand
    )
  2. T[] shuffle(T[] array, size_t delegate(size_t i) new_index)

Parameters

array T[]

array with elements to shuffle

rand double

random number generator whose generated numbers must have range ]-1..0] or [0..1[, will be invoked array.length - 1 times

Return Value

Type: T[]

shuffled array

Examples

int[] arr = [ 1, 2, 3, 4 ];
auto random_generator = () { return 0.42; }; // not proven by the dice roll
shuffle(arr, random_generator());

Meta