集册 Java实例教程 洗牌数组或数组的一部分

洗牌数组或数组的一部分

欢马劈雪     最近更新时间:2020-01-02 10:19:05

460
洗牌数组或数组的一部分
/*
nowjava 提供
*/


//package com.nowjava;

import java.util.Random;


public class Main {

    /**

     * Shuffle an array or a portion of an array

     *

     * @param array  The array to be shuffled

     * @param length The last index of the portion of the array to be shuffled

     */

    public static void shuffleArray(int[] array, int length) {

        int index, temp;

        Random random = new Random();

        for (int i = length - 1; i > 0; i--) {

            index = random.nextInt(i + 1);

    
展开阅读全文