include/marathon/random_device.h
void select(int *dst, const int n, const int k) {

            assert(k <= n);

            /**************************************************************************
             * Generate Random Combination of k out of n numbers.
             * Use Selection Sampling (see Knuth - TAoCP Section 3.4.2 Algorithm S)
             *************************************************************************/

            int t, m;
            double U;

            m = 0;
            t = 0;

            while (m < k) {

                U = nextDouble();    // U is uniformly distributed between 0 and 1

                // select t+1 with probability (n-m)/(N-t)
                if ((n - t) * U < (k - m)) {
                    dst[m] = t;
                    m++;
                }

                t++;
            }
        }
/**
         * Randomly select k integers from the range [0..n).
         * @param dst: An integer array of size k where the selected number are stored.
         * @param n: The number of integers to choose from.
         * @param k: The number of integers to choose.
         */
Randomly select k integers from the range [0..n).
@param dst: An integer array of size k where the selected number are stored.
@param n: The number of integers to choose from.
@param k: The number of integers to choose.
Randomly select k integers from the range [ 0 .. n ) . @param dst : An integer array of size k where the selected number are stored . @param n : The number of integers to choose from . @param k : The number of integers to choose .
void select(int *dst, const int n, const int k) {
            assert(k <= n);
            int t, m;
            double U;
            m = 0;
            t = 0;
            while (m < k) {
                U = nextDouble();    
                if ((n - t) * U < (k - m)) {
                    dst[m] = t;
                    m++;
                }
                t++;
            }
        }
void select ( int * dst , const int n , const int k ) { assert ( k <= n ) ; int t , m ; double U ; m = 0 ; t = 0 ; while ( m < k ) { U = nextDouble ( ) ; if ( ( n - t ) * U < ( k - m ) ) { dst [ m ] = t ; m ++ ; } t ++ ; } }
Randomly select k integers from the range [0..n).
Randomly select k integers from the range [ 0 .. n ) .
/**************************************************************************
             * Generate Random Combination of k out of n numbers.
             * Use Selection Sampling (see Knuth - TAoCP Section 3.4.2 Algorithm S)
             *************************************************************************/ // U is uniformly distributed between 0 and 1 // select t+1 with probability (n-m)/(N-t)