The OpenD Programming Language

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)
    Range
    randomShuffle
    (
    Range
    RandomGen
    )
    (
    Range r
    ,
    ref RandomGen gen
    )
    if ()
  2. Range randomShuffle(Range r)

Parameters

r Range

random-access range whose elements are to be shuffled

gen RandomGen

(optional) random number generator to use; if not specified, defaults to rndGen

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