randomShuffle

Shuffles elements of r using gen as a shuffler. r must be a random-access range with length. If no RNG is specified, rndGen will be used.

  1. Range randomShuffle(Range r, RandomGen gen)
  2. Range randomShuffle(Range r)
    Range
    randomShuffle
    (
    Range
    )
    (
    Range r
    )

Parameters

r Range

random-access range whose elements are to be shuffled

Return Value

Type: Range

The shuffled random-access range.

Examples

auto rnd = MinstdRand0(42);

auto arr = [1, 2, 3, 4, 5].randomShuffle(rnd);
version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert(arr == [3, 5, 2, 4, 1]);

Meta