Java Array Shuffle shuffleArray(Object[] array)

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

Description

shuffle Array

License

Open Source License

Declaration

public static void shuffleArray(Object[] array) 

Method Source Code

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

import java.util.Random;

public class Main {
    public static void shuffleArray(Object[] array, Random random) {
        for (int i = array.length - 1; i > 0; i--) {
            int index = random.nextInt(i + 1);
            Object obj = array[index];
            array[index] = array[i];//from w ww.  jav  a2 s .c  om
            array[i] = obj;
        }
    }

    public static void shuffleArray(int[] array, Random random) {
        for (int i = array.length - 1; i > 0; i--) {
            int index = random.nextInt(i + 1);
            int obj = array[index];
            array[index] = array[i];
            array[i] = obj;
        }
    }

    public static void shuffleArray(Object[] array) {
        shuffleArray(array, new Random());
    }
}

Related

  1. shuffleArray(int[] ar, Random rnd, int mx)
  2. shuffleArray(int[] arr)
  3. shuffleArray(int[] array, int length)
  4. shuffleArray(int[] array, long rngSeed)
  5. shuffleArray(List list)
  6. shuffleArray(T[] ar)
  7. shuffleArray(T[] arr)
  8. shuffled(List list, Random random)
  9. shuffledList(List list)