public static void shuffle(List<?> list,java.util.Random random){
  @SuppressWarnings("unchecked") final List<Object> objectList=(List<Object>)list;
  if (list instanceof RandomAccess) {
    for (int i=objectList.size() - 1; i > 0; i--) {
      int index=random.nextInt(i + 1);
      objectList.set(index,objectList.set(i,objectList.get(index)));
    }
  }
 else {
    Object[] array=objectList.toArray();
    for (int i=array.length - 1; i > 0; i--) {
      int index=random.nextInt(i + 1);
      Object temp=array[i];
      array[i]=array[index];
      array[index]=temp;
    }
    int i=0;
    ListIterator<Object> it=objectList.listIterator();
    while (it.hasNext()) {
      it.next();
      it.set(array[i++]);
    }
  }
}

public static void shuffle ( List < ? > list , java . util . Random random ) { @ SuppressWarnings ( "unchecked" ) final List < Object > objectList = ( List < Object > ) list ; if ( list instanceof RandomAccess ) { for ( int i = objectList . size ( ) - 1 ; i > 0 ; i -- ) { int index = random . nextInt ( i + 1 ) ; objectList . set ( index , objectList . set ( i , objectList . get ( index ) ) ) ; } } else { Object [ ] array = objectList . toArray ( ) ; for ( int i = array . length - 1 ; i > 0 ; i -- ) { int index = random . nextInt ( i + 1 ) ; Object temp = array [ i ] ; array [ i ] = array [ index ] ; array [ index ] = temp ; } int i = 0 ; ListIterator < Object > it = objectList . listIterator ( ) ; while ( it . hasNext ( ) ) { it . next ( ) ; it . set ( array [ i ++ ] ) ; } } }
moves every element of the list to a random new position in the list using the specified random number generator .
