shuffle

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. Returns the newly-shuffled range, and so is composable:

  1. auto shuffle(Range r, UniformRNG gen)
    shuffle
    (
    Range
    UniformRNG
    )
    (
    Range r
    ,
    UniformRNG gen
    )
    if (
    isRandomAccessRange!Range &&
    isUniformRNG!UniformRNG
    )
  2. auto shuffle(Range r)

Examples

// generates the array [0, 1, ..., 10],
// shuffles it, and writes to console
iota(10).array.shuffle.writeln;

A randomShuffle alias has been provided to ease migration from code written using $(PHOBOSXREF random, randomShuffle).

Meta