#include <stdlib.h>

/* Permute the given array. Uses random(3), so seed as desired.
 * Adapted from an algorithm written by John David Stone */
void
permute (int array[], size_t len)
{
  long swap_index;
  int temp_val;
  // Work from the end of the array forward, randomly choosing an element to
  // transpose at each location remaining
  for (long remaining = len ; remaining > 0 ; remaining--)
  { 
    swap_index = remaining * (random() / (double)RAND_MAX);
    temp_val = array[swap_index];
    array[swap_index] = array[remaining-1];
    array[remaining-1] = temp_val;
  }
} // permute
