range to sample from
random number engine to use
number of elements to include in the sample; must be less than or equal to the range.length Complexity: O(n)
RandomSample over the range.
Default RNE
// mir.ndslice package is required for 'iota', it can be found in 'mir-algorithm' static if (is(typeof({ import mir.ndslice.slice; }))) { import mir.ndslice.topology: iota; auto sample = 100.iota.sample(7); assert(sample.length == 7); }
// mir.ndslice package is required for 'iota', it can be found in 'mir-algorithm' static if (is(typeof({ import mir.ndslice.slice; }))) { import mir.algorithm.iteration: equal; import mir.ndslice.topology: iota; import mir.random.engine.xorshift; // Using pointer to RNE: setThreadLocalSeed!Xorshift(112); //Use a known seed instead of a random seed. Xorshift* gen_ptr = threadLocalPtr!Xorshift; auto sample1 = gen_ptr.sample(100.iota, 7); // Using alias of local RNE: Xorshift gen = Xorshift(112); auto sample2 = 100.iota.sample!gen(7); assert(sample1.equal(sample2)); }
Selects a random subsample out of range, containing exactly n elements. The order of elements is the same as in the original range.