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

floatrandom()
random
return random(0f, 1f);
floatrandom()
Returns a random positive float, greater than or equal to 0.0 and less than 1.0 .
return (float) Math.random();
doublerandom()
random
return Math.random() * 2 - 1;
Erandom(E[] elements)
random
return first(randomList(elements));
charrandom(final char[] chars)
Returns a random character from a sequence of characters.
int idx = rand.nextInt(chars.length);
return chars[idx];
floatrandom(float min, float max)
random
final float d = max - min;
return min + d * r.nextFloat();
floatrandom(float theStart, float theEnd)
random
final float myDiff = theEnd - theStart;
final float myRandomValue = (float) Math.random() * myDiff;
return myRandomValue + theStart;
intrandom(int min, int max)
Returns a random number
if (max - min == 0) {
    return min;
int rmin = Math.min(max, min);
int rmax = Math.max(max, min);
return random.nextInt(1 + rmax - rmin) + rmin;
Trandom(List list, Random random)
random
return list.get(random.nextInt(list.size()));
intrandom4DigitNumber()
random Digit Number
return (int) (Math.random() * 9000) + 1000;