// turn a sorted array into an almost sorted array with a given block size // assume all blocks are full blocks void permute(apvector& numbers, int blockSize) { RandGen rnd; // random number generator int positionToSwap; int temp; for(int i = 0; i < numbers.length()/blockSize; i++) for(int j = 0; j < blockSize; j++) { // the position to swap is a random integer in that block positionToSwap = rnd.RandInt(i*blockSize, i*blockSize+j); // swap the jth element of the block with the element at positionToSwap temp = numbers[positionToSwap]; numbers[positionToSwap] = numbers[i*blockSize+j]; numbers[i*blockSize+j] = temp; } }