std.random.RandomCover/randomCover
- multiple declarations
Function 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.
auto randomCover(Range, UniformRNG)
(
Range r,
auto ref UniformRNG rng
)
if (isRandomAccessRange!Range && isUniformRNG!UniformRNG);
auto randomCover(Range)
(
Range r
)
if (isRandomAccessRange!Range);
If no random number generator is passed to randomCover
, the
thread-global RNG rndGen will be used internally.
Parameters
Name | Description |
---|---|
r | random-access range to cover |
rng | (optional) random number generator to use;
if not specified, defaults to rndGen |
Returns
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.
Example
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]));
Struct 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.
struct RandomCover(Range, UniformRNG)
if (isRandomAccessRange!Range && (isUniformRNG!UniformRNG || is(UniformRNG == void)));
If no random number generator is passed to randomCover
, the
thread-global RNG rndGen will be used internally.
Parameters
Name | Description |
---|---|
r | random-access range to cover |
rng | (optional) random number generator to use;
if not specified, defaults to rndGen |
Returns
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.
Example
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]));
Authors
Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling) Ilya Yaroshenko (Mersenne Twister implementation, adapted from mir-random)