Java ThreadLocalRandom shuffleArray(int[] ar)

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

Description

shuffle Array

License

Apache License

Declaration

public static int[] shuffleArray(int[] ar) 

Method Source Code

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

import java.util.Random;

import java.util.concurrent.ThreadLocalRandom;

public class Main {
    public static int[] shuffleArray(int[] ar) {
        // If running on Java 6 or older, use `new Random()` on RHS here
        Random rnd = ThreadLocalRandom.current();
        for (int i = ar.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            // Simple swap
            int a = ar[index];
            ar[index] = ar[i];//from  w  w w .ja  v  a  2 s .com
            ar[i] = a;
        }

        return ar;
    }
}

Related

  1. randomWorld()
  2. randomWorld()
  3. shuffle(final T[] array)
  4. shuffle(T[] arr)
  5. shuffle(T[] array)
  6. timestampToMicros(final long timestampMillis)