hap.random.adaptor

Implements algorithms that transform the output of uniform random number generators into other random behaviours, such as shuffling, sampling, and so on. Typically these are implemented as range objects that wrap a provided RNG instance.

As with the random number generators provided elsewhere in this package, the range objects implemented here are implemented as final classes to enforce reference semantics. They also assume that the RNGs they make use of have reference type semantics. User-supplied value-type RNGs may result in incorrect behaviour when used with these objects.

Members

Aliases

randomCover
alias randomCover = 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.

randomSample
alias randomSample = sample

Selects a random subsample out of r, containing exactly n elements. The order of elements is the same as in the original range. The total length of r must be known. If total is passed in, the total number of elements available to sample is considered to be total. Otherwise, Sample uses r.length.

randomShuffle
alias randomShuffle = 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:

Classes

Cover
class Cover(Range, UniformRNG)

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.

Sample
class Sample(Range, UniformRNG)

Selects a random subsample out of r, containing exactly n elements. The order of elements is the same as in the original range. The total length of r must be known. If total is passed in, the total number of elements available to sample is considered to be total. Otherwise, Sample uses r.length.

Functions

cover
auto cover(Range r, UniformRNG rng)
auto cover(Range r)

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.

partialShuffle
auto partialShuffle(Range r, size_t n, UniformRNG gen)
auto partialShuffle(Range r, size_t n)

Partially shuffles the elements of r such that upon returning r[0..n] is a random subset of r and is randomly ordered. r[n..r.length] will contain the elements not in r[0..n]. These will be in an undefined order, but will not be random in the sense that their order after partialShuffle returns will not be independent of their order before partialShuffle was called.

sample
auto sample(Range r, size_t n, size_t total)
auto sample(Range r, size_t n)
auto sample(Range r, size_t n, size_t total, UniformRNG rng)
auto sample(Range r, size_t n, UniformRNG rng)

Selects a random subsample out of r, containing exactly n elements. The order of elements is the same as in the original range. The total length of r must be known. If total is passed in, the total number of elements available to sample is considered to be total. Otherwise, Sample uses r.length.

shuffle
auto shuffle(Range r, UniformRNG gen)
auto shuffle(Range r)

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:

Meta

Source

See Source File
$(HAPSRC hap/random/_adaptor.d)