Hello all,

I'm trying to understand the internal operations of the RandomSample struct in std.random.

What gets output at the end is clearly an array containing a subset of the original input. But I can't understand how this is constructed.

The constructor sets various initial values and then calls a function prime() [looks like an implementation of Knuth's Algorithm S] which returns when the current _index value is selected. Otherwise, it moves along to the next index value.

What I don't understand is where the selected values are stored or how they come to be available.

I also don't understand the corresponding randomSample functions where a specified random number generator is passed; how it can work to set ret.gen = gen _after_ the RandomSample struct has been initialized.

Can anyone help me to understand how this struct works?

Thanks & best wishes,

    -- Joe

Reply via email to