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 such that upon returning r
is a random subset of r[0..n] and is randomly ordered. r
will contain the elements not in r[n..r.length]. These will be in an undefined
order, but will not be random in the sense that their order after
r[0..n] returns will not be independent of their order before
partialShuffle was called.
partialShuffle
must be a random-access range with length. r must be less than
or equal to nr.length. If no RNG is specified, will be used.
rndGen
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
| Name | Description |
|---|---|
| r | random-access range whose elements are to be shuffled |
| n | number of elements of to shuffle (counting from the beginning);
must be less than r.length |
| gen | (optional) random number generator to use; if not
specified, defaults to |
Authors
Andrei Alexandrescu
Masahiro Nakagawa (Xorshift random generator)
Joseph Rushton Wakeling (Algorithm D for random sampling)