View source code Display the source code in std/random.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.random.partialShuffle

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.

r must be a random-access range with length. n must be less than or equal to r.length. If no RNG is specified, rndGen will be used.

Prototypes

void partialShuffle(Range, RandomGen)(
  Range r,
  size_t n,
  RandomGen gen
)
if (isRandomAccessRange!Range && isUniformRNG!RandomGen);

void partialShuffle(Range)(
  Range r,
  size_t n
)
if (isRandomAccessRange!Range);

Parameters

NameDescription
r random-access range whose elements are to be shuffled
n number of elements of r to shuffle (counting from the beginning); must be less than r.length
gen (optional) random number generator to use; if not specified, defaults to rndGen

Authors

Andrei Alexandrescu Masahiro Nakagawa (Xorshift random generator) Joseph Rushton Wakeling (Algorithm D for random sampling)

License

Boost License 1.0.

Comments