Java Array Shuffle shuffleArray(double[] ar)

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

Description

Implementing Fisher-Yates shuffle

License

Open Source License

Parameter

Parameter Description
ar double array to be shuffled

Declaration

static void shuffleArray(double[] ar) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    /**//from w ww  .  j av  a  2  s.c  o m
     * Implementing Fisher-Yates shuffle
     * @param ar double array to be shuffled
     */
    static void shuffleArray(double[] ar) {
        Random rnd = new Random();
        for (int i = ar.length - 1; i >= 0; i--) {
            int index = rnd.nextInt(i + 1);
            // Simple swap
            double a = ar[index];
            ar[index] = ar[i];
            ar[i] = a;
        }
    }
}

Related

  1. shuffle(T[] array)
  2. shuffle(T[] array, Random rand)
  3. shuffle(T[] array, Random rand)
  4. shuffle(T[] array, Random random)
  5. shuffle(T[] data)
  6. shuffleArray(int arr[])
  7. shuffleArray(int[] a)
  8. shuffleArray(int[] ar)
  9. shuffleArray(int[] ar)