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

StringgetRandomUUID()
get Random UUID
UUID uuid = UUID.randomUUID();
return uuid.toString();
booleanisRandomList(List list)
is Random List
return (list instanceof RandomAccess);
IntegermedianHelper(List list, int k, Random r)
median Helper
Integer pivot;
int numPivots = 0;
List<Integer> less, greater;
ListIterator<Integer> iter;
if (list.size() == 1) {
    return list.get(0);
less = new LinkedList<Integer>();
...
intmultSample(Random rng, double[] vals, double normsum)
Draw a multinomial sample from (un-normalized) vals
double rval = rng.nextDouble() * normsum;
double cumsum = 0;
int j = 0;
while (cumsum < rval || j == 0) {
    cumsum += vals[j];
    j++;
return j - 1;
...
voidpermute(Object[] arr, Random random)
Fischer-Yates shuffling algorithm for permuting the contents of a coordinate array.
for (int i = arr.length - 1; i > 0; i--) {
    int j = random.nextInt(i + 1);
    swap(arr, i, j);
intrand()
pseudo-random number based on linear congruential method
holdrand_ = holdrand_ * 214013L + 2531011L;
return (int) ((holdrand_ >> 16) & 0x7fff);
floatRand()
Rand
final float ra;
ra = (float) (Math.random() - 0.5);
return (ra);
floatrandAngle()
rand Angle
return (float) (Math.random() * 2.0 * Math.PI);
floatrandFloat(float min, float max)
rand Float
return (float) (min + Math.random() * ((1 + max) - min));
doublerandom()
random
return Math.random();