RandSeq { public <T> List<T> reorder( List<T> sequence) { int elementCount = sequence.size(); if( elementCount > 1) { List<T> elements = new ArrayList<T>( sequence); sequence.clear(); for( ; elementCount > 0; elementCount--) { sequence.add( elements.remove( generator_.nextInt( elementCount))); } } return sequence; } RandSeq( Random generator);  RandSeq();  RandSeq( long seed); List<T> reorder( List<T> sequence); Iterator<T> reorder( Iterator<T> sequence); static List<T> reorderIf( RandSeq randSeq, List<T> sequence); static List<T> order( RandSeq randSeq, Collection<T> collection); static Iterator<T> reorderIf( RandSeq randSeq, Iterator<T> sequence);  }
@Test public void testReorderList() { RandSeq randSeq1 = new RandSeq( getClass().hashCode()); Integer[] elements = new Integer[] {1, 2, 3, 5, 8, 13, 21}; List<Integer> sequence1 = randSeq1.reorder( new ArrayList<Integer>( Arrays.asList( elements))); assertThat( "New sequence", sequence1, containsMembers( elements)); RandSeq randSeq2 = new RandSeq( new Random( getClass().hashCode())); List<Integer> sequence2 = randSeq2.reorder( new ArrayList<Integer>( Arrays.asList( elements))); assertThat( "Same seed", sequence2, listsMembers( sequence1)); }
@Test public void testReorderIterator() { RandSeq randSeq = new RandSeq( RandSeq.class.hashCode()); Integer[] elements = new Integer[] {1, 2, 3, 5, 8, 13, 21}; Iterator<Integer> sequence = randSeq.reorder( Arrays.asList( elements).iterator()); assertThat( "New sequence", sequence, visitsMembers( elements)); }