The OpenD Programming Language

mir.random.algorithm

Public Imports

mir.random.engine
public import mir.random.engine;
Undocumented in source.

Members

Functions

randomSlice
auto randomSlice(G gen, D var, size_t[N] lengths)
auto randomSlice(G* gen, D var, size_t[N] lengths)
auto randomSlice(D var, size_t[N] lengths)
auto randomSlice(G gen, size_t[N] lengths)
auto randomSlice(G* gen, size_t[N] lengths)
auto randomSlice(size_t[N] lengths)

Allocates ndslice (vector, matrix, or tensor) and fills it with random numbers. If no variable is specified each element e is generated per rand!(typeof(e)).

sample
auto sample(G gen, Range range, size_t n)
auto sample(G* gen, Range range, size_t n)
auto sample(Range range, size_t n)

Selects a random subsample out of range, containing exactly n elements. The order of elements is the same as in the original range.

shuffle
void shuffle(G gen, Slice!Iterator range)
void shuffle(G* gen, Slice!Iterator range)
void shuffle(Slice!Iterator range)

Shuffles elements of range.

shuffle
void shuffle(G gen, Slice!Iterator range, size_t n)
void shuffle(G* gen, Slice!Iterator range, size_t n)
void shuffle(Slice!Iterator range, size_t n)

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

Structs

RandomSample
struct RandomSample(G, Range)
struct RandomSample(Range, alias gen)

Lazy input or forward range containing a random sample. VitterStrides is used to skip elements. Complexity: O(n) Note:

  • The structure holds a pointer to a generator.
  • The structure must not be copied (explicitly or implicitly) outside from a function.
VitterStrides
struct VitterStrides

Random sampling utility. Complexity: O(n) References: Jeffrey Scott Vitter, An efficient algorithm for sequential random sampling

Meta

Authors

Ilya Yaroshenko, documentation is partially based on Phobos.

License

Boost License 1.0.

This module is available in the extended configuration.