Java Array Shuffle shuffle(int arr[])

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

Description

shuffle

License

LGPL

Declaration

public static void shuffle(int arr[]) 

Method Source Code


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

import java.util.*;

public class Main {
    private static Random r;

    public static void shuffle(int arr[]) {
        Random rnd = r;/* ww  w  .  j  a v  a  2  s  .  com*/
        if (rnd == null) {
            r = rnd = new Random();
        }

        for (int i = arr.length; i > 1; i--) {
            int nextInt = rnd.nextInt(i);
            int tmp = arr[i - 1];
            arr[i - 1] = arr[nextInt];
            arr[nextInt] = tmp;
        }
    }
}

Related

  1. shuffle(final Object[] values)
  2. shuffle(final T[] arr)
  3. shuffle(final T[] array)
  4. shuffle(final T[] array)
  5. shuffle(int a[])
  6. shuffle(int size, boolean reallyShuffle)
  7. shuffle(int[] a)
  8. shuffle(int[] arr)
  9. shuffle(int[] arr)