Java Array Shuffle shuffleArray(int[] ar, Random rnd, int mx)

Here you can find the source of shuffleArray(int[] ar, Random rnd, int mx)

Description

shuffle Array

License

LGPL

Declaration

public static void shuffleArray(int[] ar, Random rnd, int mx) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.Random;

public class Main {
    public static void shuffleArray(int[] ar, Random rnd, int mx) {

        for (int i = mx; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            // Simple swapArray
            int a = ar[index];

            ar[index] = ar[i];/*from w w  w  . j  av a2 s.  c  o m*/
            ar[i] = a;
        }
    }

    public static void shuffleArray(int[] ar, Random rnd) {
        shuffleArray(ar, rnd, ar.length - 1);
    }
}

Related

  1. shuffleArray(double[] ar)
  2. shuffleArray(int arr[])
  3. shuffleArray(int[] a)
  4. shuffleArray(int[] ar)
  5. shuffleArray(int[] ar)
  6. shuffleArray(int[] arr)
  7. shuffleArray(int[] array, int length)
  8. shuffleArray(int[] array, long rngSeed)
  9. shuffleArray(List list)