src/fundamentals/programming_model/Sattolo.java
/**
     * Rearranges an array of objects to be a uniformly random cycle (under the
     * assumption that <tt>Math.random()</tt> generates independent and
     * uniformly distributed numbers between 0 and 1).
     *
     * @param a the array to be rearranged
     * @see StdRandom
     */
Rearranges an array of objects to be a uniformly random cycle (under the
assumption that Math.random() generates independent and
uniformly distributed numbers between 0 and 1).

@param a the array to be rearranged
@see StdRandom
Rearranges an array of objects to be a uniformly random cycle ( under the assumption that Math . random () generates independent and uniformly distributed numbers between 0 and 1 ) . @param a the array to be rearranged @see StdRandom
public static void cycle(Object[] a) {
        int N = a.length;
        for (int i = N; i > 1; i--) {
            int r = (int) (Math.random() * (i - 1));
            Object swap = a[r];
            a[r] = a[i - 1];
            a[i - 1] = swap;
        }
    }
public static void cycle ( Object [ ] a ) { int N = a . length ; for ( int i = N ; i > 1 ; i -- ) { int r = ( int ) ( Math . random ( ) * ( i - 1 ) ) ; Object swap = a [ r ] ; a [ r ] = a [ i - 1 ] ; a [ i - 1 ] = swap ; } }
Rearranges an array of objects to be a uniformly random cycle (under the
 assumption that <tt>Math.random()</tt> generates independent and
 uniformly distributed numbers between 0 and 1).
Rearranges an array of objects to be a uniformly random cycle ( under the assumption that <tt > Math . random () < / tt > generates independent and uniformly distributed numbers between 0 and 1 ) .
// choose index uniformly in [0, i-1)
