cover

Covers a given range r in a random manner, i.e. goes through each element of r once and only once, but in a random order. r must be a random-access range with length.

If no random number generator is passed to cover, the thread-global RNG rndGen will be used as the source of randomness.

  1. auto cover(Range r, UniformRNG rng)
    cover
    (
    Range
    UniformRNG
    )
    (
    Range r
    ,
    UniformRNG rng
    )
    if (
    isRandomAccessRange!Range &&
    isUniformRNG!UniformRNG
    )
  2. auto cover(Range r)

Examples

int[] a = [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ];
foreach (e; cover(a))
{
    writeln(e);
}

// using a specified random number generator
auto gen = new Random(unpredictableSeed);
foreach (e; cover(a, gen))
{
    writeln(e);
}

The alias randomCover is available to ease migration for code written using $(PHOBOSXREF random, randomCover).

Meta