Example usage for java.util Collections shuffle

List of usage examples for java.util Collections shuffle

Introduction

In this page you can find the example usage for java.util Collections shuffle.

Prototype

public static void shuffle(List<?> list) 

Source Link

Document

Randomly permutes the specified list using a default source of randomness.

Usage

From source file:edu.cmu.tetrad.search.TestHippocampus.java

int[] shuffle(int[] arr) {
    List<Integer> list = new ArrayList<Integer>();

    for (int i = 1; i <= arr.length; i++) {
        list.add(i);/*from w  w  w .  j a  v  a 2s  .c  o  m*/
    }

    Collections.shuffle(list);

    int[] arr2 = new int[arr.length];

    for (int i = 0; i < list.size(); i++) {
        arr2[i] = list.get(i);
    }

    return arr2;
}