Java Array Shuffle shuffleArray(int[] arr)

Here you can find the source of shuffleArray(int[] arr)

Description

shuffle Array

License

Open Source License

Declaration

public static void shuffleArray(int[] arr) 

Method Source Code

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

import java.util.Random;

public class Main {
    public static void shuffleArray(int[] arr) {
        int n = arr.length;
        Random rnd = new Random();
        for (int i = 0; i < n; i++) {
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n - i);
            arr[i] = arr[randomPos];/*  w  ww .  j a v a 2  s.com*/
            arr[randomPos] = tmp;
        }
    }
}

Related

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