Java Utililty Methods Random

List of utility methods to do Random

Description

The list of methods to do Random are organized into topic(s).

Method

ListrandomUniformUniqueIntegerList(int sz)
random Uniform Unique Integer List
List<Integer> lst = new ArrayList<>(sz);
for (int i = 0; i < sz; i++)
    lst.add(i);
Collections.shuffle(lst);
return lst;
StringrandomValue()
random Value
double currentTimeMillis = System.currentTimeMillis() * Math.random();
return String.valueOf(Math.round(currentTimeMillis));
TrandomValue(T[] array)
random Value
int index = (int) (Math.random() * array.length);
return array[index];
int[]randomVector(int size)
Creates a random vector of integers of length size
return randomVector(size, Integer.MAX_VALUE);
RandomrandRandom(Random random)
rand Random
return new Random(random.nextInt(Integer.MAX_VALUE));
floatrandRange(float from, float to)
rand Range
return ((float) Math.random() * (to - from)) + from;
floatrandRangeDecimal(float min, float max)
Calculates a random number within a minimum and maximum range.
return (float) Math.random() * (max - min) + min;
voidresetRandomGenerator()
reset Random Generator
randomGenerator.setSeed(GATK_RANDOM_SEED);
DrunProbability(Random rng, float[] probs, D[] choices)
run Probability
float tProb = 0;
for (int i = 0; i < probs.length; i++) {
    tProb += probs[i];
float s = rng.nextFloat() * tProb;
int c = 0;
for (int i = 0; i < probs.length; i++) {
    s -= probs[i];
...