测试

e:\vim\java\Shuffle.java.html

import java.util.*;

public class Shuffle
{
    public static int[] getShuffle(int[] orderArray)
    {
        int length = orderArray.length;
        int[] newArray = new int[length];

        int randCount = 0;
        int position;
        int k=0;

        Random rand = new Random();

        while(randCount<length)
        {
            int range = length - randCount;
            position = rand.nextInt(range);
            newArray[k++] = orderArray[position];
            orderArray[position] = orderArray[range-1];
            randCount++;
        }
        return newArray;
    }

    public static void main(String[] args)
    {
        int[] arr = new int[10];
        for(int i=0; i<10; i++)
            arr[i] = i;

        int[] newArr = getShuffle(arr);
        for(int i=0; i<10; i++)
            System.out.print(newArr[i]);
    }
}
原文地址:https://www.cnblogs.com/wouldguan/p/3022246.html