Java Random randomPermutations(int[] tab, Random r)

Here you can find the source of randomPermutations(int[] tab, Random r)

Description

random Permutations

License

Open Source License

Declaration

public static int[] randomPermutations(int[] tab, Random r) 

Method Source Code


//package com.java2s;
import java.util.*;

public class Main {
    public static int[] randomPermutations(int[] tab, Random r) {
        int l = tab.length;
        for (int i = 0; i < l; i++) {
            int j = r.nextInt(l);
            int tmp = tab[i];
            tab[i] = tab[j];//  ww  w .  ja  v  a  2  s.  c  o m
            tab[j] = tmp;
        }
        return tab;
    }

    public static int[] randomPermutations(int[] tab, long seed) {
        return randomPermutations(tab, new Random(seed));
    }

    public static <E> E[] randomPermutations(E[] tab, Random r) {
        int l = tab.length;
        for (int i = 0; i < l; i++) {
            int j = r.nextInt(l);
            E tmp = tab[i];
            tab[i] = tab[j];
            tab[j] = tmp;
        }
        return tab;
    }

    public static <E> E[] randomPermutations(E[] tab, long seed) {
        return randomPermutations(tab, new Random(seed));
    }
}

Related

  1. randomMember(Collection collection)
  2. randomNanoTime()
  3. randomNick()
  4. randomPassword()
  5. randomPermutation(int size)
  6. randomPermute(List l, Random rand)
  7. randomProbability(double probability)
  8. randomPseudo()
  9. randomRange(int end)