Sigh, don't have an SO account but if I did, I would suggest this code which I call randsort --
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[]) {
int i, ndx;
double my_numbers[10];
double sorted_numbers[10];
uint16_t picked;
for (i = 1; i < argc; i++) {
my_numbers[i-1] = atof(argv[i]);
}
while (1) {
picked = 0;
ndx = 0;
/* sort the numbers */
while (picked != 0x3ff) {
i = (rand() / 100) % 10;
if ((picked & (1 << i)) == 0) {
picked |= (1 << i);
sorted_numbers[ndx++] = my_numbers[i];
}
}
/* verify they sorted correctly */
for (i = 8; i >= 0; i--) {
if (( i == -1) || (sorted_numbers[i] > sorted_numbers[i+1])) {
break;
}
}
if (i == -1) {
printf(" Sorted: \n");
for (i = 0; i < 10; i++) {
printf(" %d: %f\n", i, sorted_numbers[i]);
}
exit(0);
}
}
}