Java Array Shuffle shuffle(int size, boolean reallyShuffle)

Here you can find the source of shuffle(int size, boolean reallyShuffle)

Description

shuffle

License

Open Source License

Declaration

public static ArrayList<Integer> shuffle(int size, boolean reallyShuffle) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;

public class Main {
    public static ArrayList<Integer> shuffle(int size, boolean reallyShuffle) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        if (reallyShuffle) {
            HashSet<Integer> shuffled = new HashSet<Integer>();
            Random r = new Random();
            while (result.size() != size) {
                int i = r.nextInt(size);
                if (shuffled.add(i)) {
                    result.add(i);//from w  w w. jav a2  s .com
                }
            }
        } else {
            for (int i = 0; i < size; i++)
                result.add(i);
        }
        return result;
    }
}

Related

  1. shuffle(final T[] arr)
  2. shuffle(final T[] array)
  3. shuffle(final T[] array)
  4. shuffle(int a[])
  5. shuffle(int arr[])
  6. shuffle(int[] a)
  7. shuffle(int[] arr)
  8. shuffle(int[] arr)
  9. shuffle(int[] array)