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.

  1. auto randomCover(Range r, UniformRNG rng)
    randomCover
    (
    Range
    UniformRNG
    )
    (
    Range r
    ,
    auto ref UniformRNG rng
    )
    if (
    isUniformRNG!UniformRNG
    )
  2. auto randomCover(Range r)

Parameters

r Range

random-access range to cover

rng UniformRNG

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

Return Value

Type: auto

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