Java Array Shuffle shuffle(Object[] array)

Here you can find the source of shuffle(Object[] array)

Description

shuffle

License

Artistic License

Declaration

public static void shuffle(Object[] array) 

Method Source Code


//package com.java2s;
//License from project: Artistic License 

import java.util.Random;

public class Main {
    private static final Random RANDOM = new Random();

    public static void shuffle(Object[] array) {
        for (int i = 0; i < array.length; i++) {
            /*/*from   w  w w  .  ja v a  2s  . c om*/
             * RANDOM.nextInt(n) restituisce un int casuale compreso tra 0 e n (escluso)
             */
            int nuovaPosizione = RANDOM.nextInt(array.length);
            Object swap = array[nuovaPosizione];

            array[nuovaPosizione] = array[i];
            array[i] = swap;
        }
    }
}

Related

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