RandomCover

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

If no random number generator is passed to randomCover, the thread-global RNG rndGen will be used internally.

struct RandomCover (
Range
UniformRNG = void
) if (
isRandomAccessRange!Range &&
(
isUniformRNG!UniformRNG ||
is(UniformRNG == void)
)
) {}

Return Value

Range whose elements consist of the elements of r, in random order. Will be a forward range if both r and rng are forward ranges, an input range otherwise.

Examples

import std.algorithm.comparison : equal;
import std.range : iota;
auto rnd = MinstdRand0(42);

version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert(10.iota.randomCover(rnd).equal([7, 4, 2, 0, 1, 6, 8, 3, 9, 5]));

Meta