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

floatrandomFloat(float aVal)
Returns a random float up to given value.
return Math.abs(_random.nextInt()) / (float) Integer.MAX_VALUE * aVal;
floatrandomFloat(float min, float max)
random Float
return (float) (Math.random() * (max - min) + min);
floatrandomFloatBetween(float begin, float end)
random Float Between
float rand = (float) Math.random();
return begin + (rand * ((end - begin)));
TrandomFromIterator(Iterator iter)
random From Iterator
if (!iter.hasNext()) {
    return null;
T element = iter.next();
double seen = 1;
while (iter.hasNext()) {
    seen += 1;
    T posReplace = iter.next();
...
ListrandomGaussian(int numElements)
random Gaussian
return randomGaussian(numElements, 1.0);
double[]randomGreyLevels(double max, double min)
random Grey Levels
double del = max - min;
double[] ret = new double[224 * 65];
for (int i = 0; i < ret.length; i++) {
    ret[i] = del * RND.nextDouble() + min;
return ret;
StringrandomIcon()
random Icon
int min = 1, max = 24;
return String.format("https://coding.net/static/project_icon/scenery-%d.png",
        min + (int) (Math.random() * ((max - min) + 1)));
StringrandomID()
Generate a random ID.
return System.currentTimeMillis() + "";
StringrandomId()
Create and return an ID that's (virtually) guaranteed not to name a real object on a GA4GH server.
return UUID.randomUUID().toString();
int[]randomIndices(Random r, int minCount, int maxCount)
random Indices
minCount = Math.max(Math.min(minCount, maxCount), 1);
maxCount = Math.max(minCount, maxCount);
List<Integer> tmp = new ArrayList<>(maxCount);
for (int i = 0; i < maxCount; i++) {
    tmp.add(i);
Collections.shuffle(tmp);
final int outputCount = minCount + r.nextInt(maxCount - minCount);
...