Java Array Shuffle shuffle(int[] array)

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

Description

Shuffles the array given.

License

Open Source License

Parameter

Parameter Description
array the array to shuffle

Declaration

public static void shuffle(int[] array) 

Method Source Code


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

import java.util.Random;

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

    /**/*from www. ja va2  s.  com*/
     * Shuffles the array given.
     *
     * @param array the array to shuffle
     */
    public static void shuffle(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            int j = rand.nextInt(i + 1);
            int temp = array[j];
            array[j] = array[i];
            array[i] = temp;
        }
    }
}

Related

  1. shuffle(int[] a)
  2. shuffle(int[] arr)
  3. shuffle(int[] arr)
  4. shuffle(int[] array)
  5. shuffle(int[] array)
  6. shuffle(int[] array)
  7. shuffle(int[] array)
  8. shuffle(int[] array, Random rand)
  9. shuffle(int[] array, Random rand)