Java Array Shuffle shuffle(Object[] a, Random r)

Here you can find the source of shuffle(Object[] a, Random r)

Description

shuffle array

License

Open Source License

Declaration

public static void shuffle(Object[] a, Random r) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**//from  www.  ja va 2  s .c om
     * shuffle array
     */
    public static void shuffle(Object[] a, Random r) {
        for (int n = 0; n < a.length; n++) {
            // don't just pick random position!
            int x = r.nextInt(a.length - n) + n;
            Object o = a[n];
            a[n] = a[x];
            a[x] = o;
        }
    }
}

Related

  1. shuffle(List as)
  2. shuffle(List list)
  3. shuffle(List list)
  4. shuffle(List list, int nswaps)
  5. shuffle(Object[] a)
  6. shuffle(Object[] array)
  7. shuffle(Object[] objs, Random random, int start, int len)
  8. shuffle(Random rand, O[] array)
  9. shuffle(short... a)