public static int [ ] randomPermutation ( final int [ ] out , Random random ) { for ( int i = out . length - 1 ; i > 0 ; i -- ) { // Swap with random preceeding element. int ri = random . nextInt ( i + 1 ) ; int tmp = out [ ri ] ; out [ ri ] = out [ i ] ; out [ i ] = tmp ; } return out ; }
Perform a random permutation of the array in - place .