#include static void swap(int& i, int& j) { int temp = i; i = j; j = temp; } static int randSlot(int i) { // return a random int from 0 to i inclusive double r = double(rand())/RAND_MAX; int retVal = int(r*(i+1)); if(retVal > i) { return 0; } return retVal; } int* permList(int sz) { int *retVal = new int[sz]; int i; for(i = 0; i < sz; i++) { // put all the numbers in retVal[i] = i; } for(i--; i > 0; i--) { // choose the value of each slot in desc. order swap(retVal[i], retVal[randSlot(i)]); } return retVal; }