pub fn choose<T>(r: &mut Rng, dest: &mut [T], src: &[T]) -> Value
Expand description

This function fills the array dest[k] with k objects taken randomly from the n elements of the array src[0..n-1]. The objects are each of size size. The output of the random number generator r is used to make the selection. The algorithm ensures all possible samples are equally likely, assuming a perfect source of randomness.

The objects are sampled without replacement, thus each object can only appear once in dest[k]. It is required that k be less than or equal to n. The objects in dest will be in the same relative order as those in src. You will need to call gsl_ran_shuffle(r, dest, n, size) if you want to randomize the order.

The following code shows how to select a random sample of three unique numbers from the set 0 to 99,

double a[3], b[100];
 
for (i = 0; i < 100; i++)
  {
    b[i] = (double) i;
  }
 
gsl_ran_choose (r, a, 3, b, 100, sizeof (double));