pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
where R: Rng + ?Sized {
    if amount > length {
        panic!("`amount` of samples must be less than or equal to `length`");
    }
    if length > (::core::u32::MAX as usize) {
        // We never want to use inplace here, but could use floyd's alg
        // Lazy version: always use the cache alg.
        return sample_rejection(rng, length, amount);
    }
    let amount = amount as u32;
    let length = length as u32;

    // Choice of algorithm here depends on both length and amount. See:
    // https://github.com/rust-random/rand/pull/479
    // We do some calculations with f32. Accuracy is not very important.

    if amount < 163 {
        const C: [[f32; 2]; 2] = [[1.6, 8.0 / 45.0], [10.0, 70.0 / 9.0]];
        let j = if length < 500_000 { 0 } else { 1 };
        let amount_fp = amount as f32;
        let m4 = C[0][j] * amount_fp;
        // Short-cut: when amount < 12, floyd's is always faster
        if amount > 11 && (length as f32) < (C[1][j] + m4) * amount_fp {
            sample_inplace(rng, length, amount)
        } else {
            sample_floyd(rng, length, amount)
        }
    } else {
        const C: [f32; 2] = [270.0, 330.0 / 9.0];
        let j = if length < 500_000 { 0 } else { 1 };
        if (length as f32) < C[j] * (amount as f32) {
            sample_inplace(rng, length, amount)
        } else {
            sample_rejection(rng, length, amount)
        }
    }
}
/// Randomly sample exactly `amount` distinct indices from `0..length`, and
/// return them in random order (fully shuffled).
///
/// This method is used internally by the slice sampling methods, but it can
/// sometimes be useful to have the indices themselves so this is provided as
/// an alternative.
///
/// The implementation used is not specified; we automatically select the
/// fastest available algorithm for the `length` and `amount` parameters
/// (based on detailed profiling on an Intel Haswell CPU). Roughly speaking,
/// complexity is `O(amount)`, except that when `amount` is small, performance
/// is closer to `O(amount^2)`, and when `length` is close to `amount` then
/// `O(length)`.
///
/// Note that performance is significantly better over `u32` indices than over
/// `u64` indices. Because of this we hide the underlying type behind an
/// abstraction, `IndexVec`.
///
/// If an allocation-free `no_std` function is required, it is suggested
/// to adapt the internal `sample_floyd` implementation.
///
/// Panics if `amount > length`.
Randomly sample exactly `amount` distinct indices from `0..length`, and
return them in random order (fully shuffled).

This method is used internally by the slice sampling methods, but it can
sometimes be useful to have the indices themselves so this is provided as
an alternative.

The implementation used is not specified; we automatically select the
fastest available algorithm for the `length` and `amount` parameters
(based on detailed profiling on an Intel Haswell CPU).

Note that performance is significantly better over `u32` indices than over
`u64` indices. Because of this we hide the underlying type behind an
abstraction, `IndexVec`.

If an allocation-free `no_std` function is required, it is suggested
to adapt the internal `sample_floyd` implementation.

Panics if `amount > length`.
Randomly sample exactly ` amount ` distinct indices from ` 0 .. length ` and return them in random order ( fully shuffled ) . This method is used internally by the slice sampling methods but it can sometimes be useful to have the indices themselves so this is provided as an alternative . The implementation used is not specified ; we automatically select the fastest available algorithm for the ` length ` and ` amount ` parameters ( based on detailed profiling on an Intel Haswell CPU ) . Note that performance is significantly better over ` u32 ` indices than over ` u64 ` indices . Because of this we hide the underlying type behind an abstraction ` IndexVec ` . If an allocation - free ` no_std ` function is required it is suggested to adapt the internal ` sample_floyd ` implementation . Panics if ` amount > length ` .
pub fn sample<R>(rng: &mut R, length: usize, amount: usize) -> IndexVec
where R: Rng + ?Sized {
    if amount > length {
        panic!("`amount` of samples must be less than or equal to `length`");
    }
    if length > (::core::u32::MAX as usize) {
        // We never want to use inplace here, but could use floyd's alg
        // Lazy version: always use the cache alg.
        return sample_rejection(rng, length, amount);
    }
    let amount = amount as u32;
    let length = length as u32;
    // Choice of algorithm here depends on both length and amount. See:
    // https://github.com/rust-random/rand/pull/479
    // We do some calculations with f32. Accuracy is not very important.
    if amount < 163 {
        const C: [[f32; 2]; 2] = [[1.6, 8.0 / 45.0], [10.0, 70.0 / 9.0]];
        let j = if length < 500_000 { 0 } else { 1 };
        let amount_fp = amount as f32;
        let m4 = C[0][j] * amount_fp;
        // Short-cut: when amount < 12, floyd's is always faster
        if amount > 11 && (length as f32) < (C[1][j] + m4) * amount_fp {
            sample_inplace(rng, length, amount)
        } else {
            sample_floyd(rng, length, amount)
        }
    } else {
        const C: [f32; 2] = [270.0, 330.0 / 9.0];
        let j = if length < 500_000 { 0 } else { 1 };
        if (length as f32) < C[j] * (amount as f32) {
            sample_inplace(rng, length, amount)
        } else {
            sample_rejection(rng, length, amount)
        }
    }
}
pub fn sample < R > ( rng : & mut R , length : usize , amount : usize ) -> IndexVec where R : Rng + ? Sized { if amount > length { panic ! ( " " ) ; } if length > ( :: core :: u32 :: MAX as usize ) { // We never want to use inplace here, but could use floyd's alg // Lazy version: always use the cache alg. return sample_rejection ( rng , length , amount ) ; } let amount = amount as u32 ; let length = length as u32 ; // Choice of algorithm here depends on both length and amount. See: // https://github.com/rust-random/rand/pull/479 // We do some calculations with f32. Accuracy is not very important. if amount < 163 { const C : [ [ f32 ; 2 ] ; 2 ] = [ [ 1.6 , 8.0 / 45.0 ] , [ 10.0 , 70.0 / 9.0 ] ] ; let j = if length < 500_000 { 0 } else { 1 } ; let amount_fp = amount as f32 ; let m4 = C [ 0 ] [ j ] * amount_fp ; // Short-cut: when amount < 12, floyd's is always faster if amount > 11 && ( length as f32 ) < ( C [ 1 ] [ j ] + m4 ) * amount_fp { sample_inplace ( rng , length , amount ) } else { sample_floyd ( rng , length , amount ) } } else { const C : [ f32 ; 2 ] = [ 270.0 , 330.0 / 9.0 ] ; let j = if length < 500_000 { 0 } else { 1 } ; if ( length as f32 ) < C [ j ] * ( amount as f32 ) { sample_inplace ( rng , length , amount ) } else { sample_rejection ( rng , length , amount ) } } }
Randomly sample exactly `amount` distinct indices from `0..length`, and
return them in random order (fully shuffled).
Randomly sample exactly ` amount ` distinct indices from ` 0 .. length ` and return them in random order ( fully shuffled ) .
rng
&mut R
length
usize
amount
usize