Function PGARandomSampleInit
Defined in File random.c
Function Documentation
-
void PGARandomSampleInit(PGAContext *ctx, PGASampleState *state, int k, int n)
Init random sampling of k out of n without replacement.
Description
Algorithm from [Vit87]. This is implemented as an iterator, i.e., this init method that initializes
nandkand a functionPGARandomNextSample()that returns the next sample index. The algorithm guarantees that sample indexes are returned sorted in index order. Note that the internal implementation variableCUTOFFis arbitrary and no measurements were performed – modern CPUs can probably iterate a lot when not accessing memory, so this can probably be set a lot higher.Example
PGAContext *ctx; PGASampleState state; int s; ... PGARandomSampleInit (ctx, &state, 3, 6); s = PGARandomNextSample (&state);
- Parameters:
ctx – context variable
state – pointer to PGASampleState, needs to be allocated by caller
k – k of the k out of n
n – n of the k out of n
- Returns:
None