Search this API

y.util
Class YRandom

java.lang.Object
  extended by java.util.Random
      extended by y.util.YRandom
All Implemented Interfaces:
java.io.Serializable

public class YRandom
extends java.util.Random

Generates pseudo-random numbers and the such.

See Also:
Serialized Form
 

Constructor Summary
YRandom()
          Creates a new instance of this class.
YRandom(long seed)
          Creates a new instance of this class with a given initial random seed.
 
Method Summary
 boolean[] getBoolArray(int n, int trueCount)
          Returns an array of n randomly chosen boolean values of which trueCount of them are true.
 int[] getIntArray(int bucketCount, int ballCount)
          Returns an int array of length bucketCount for which the values of all fields are non-negative and sum up to ballCount.
 int[] getUniqueArray(int n, int min, int max)
          Returns an array of n unique random integers that lie within the range min (inclusive) and max (exclusive).
 double nextDouble(double minValue, double maxValue)
          Returns a double with a random value between minValue (inclusive) and maxValue (exclusive).
 int nextInt(int n)
          Returns a pseudo-random, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
 int nextInt(int minValue, int maxValue)
          Returns an int with a random value between minValue (inclusive) and maxValue (exclusive).
 void permutate(java.lang.Object[] a)
          Permutes the positions of the elements within the given array.
 
Methods inherited from class java.util.Random
next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextLong, setSeed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

YRandom

public YRandom()
Creates a new instance of this class.


YRandom

public YRandom(long seed)
Creates a new instance of this class with a given initial random seed.

Method Detail

nextInt

public int nextInt(int n)
Returns a pseudo-random, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Overrides:
nextInt in class java.util.Random

getUniqueArray

public int[] getUniqueArray(int n,
                            int min,
                            int max)
Returns an array of n unique random integers that lie within the range min (inclusive) and max (exclusive). If max - min < n then null is returned.


getBoolArray

public boolean[] getBoolArray(int n,
                              int trueCount)
Returns an array of n randomly chosen boolean values of which trueCount of them are true. If the requested numbers of true values is bigger than the number of requested boolean values, an Exception is raised.


getIntArray

public int[] getIntArray(int bucketCount,
                         int ballCount)
Returns an int array of length bucketCount for which the values of all fields are non-negative and sum up to ballCount. The values are put in the array randomly.


nextDouble

public double nextDouble(double minValue,
                         double maxValue)
Returns a double with a random value between minValue (inclusive) and maxValue (exclusive).

Precondition:
maxValue > minValue

nextInt

public int nextInt(int minValue,
                   int maxValue)
Returns an int with a random value between minValue (inclusive) and maxValue (exclusive).

Precondition:
maxValue > minValue

permutate

public void permutate(java.lang.Object[] a)
Permutes the positions of the elements within the given array.


© Copyright 2000-2022,
yWorks GmbH.
All rights reserved.