Package de.tilman_neumann.jml.base
Class Rng
java.lang.Object
java.util.Random
de.tilman_neumann.jml.base.Rng
- All Implemented Interfaces:
java.io.Serializable
public class Rng
extends java.util.Random
Generator for pseudo-random natural and floating point numbers.
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description java.math.BigDecimal
nextBigDecimal(java.math.BigDecimal maxValue, int resultScale)
Generates a BigDecimal from [0, maxValue) with the given number of decimal digits after the floating point.java.math.BigDecimal
nextBigDecimal(java.math.BigDecimal maxValue, int minScale, int maxScale)
Generates a BigDecimal from U[0, maxValue) with minDigits...maxDigits decimal digits after the floating point.java.math.BigDecimal
nextBigDecimal(java.math.BigDecimal minValue, java.math.BigDecimal maxValue, int minScale, int maxScale)
Generates a BigDecimal from U[minValue, maxValue) with minDigits...maxDigits decimal digits after the floating point.java.math.BigInteger
nextBigInteger(int maxBits)
Get uniformly distributed random integer with the specified maximum number of bits, i.e.java.math.BigInteger
nextBigInteger(java.math.BigInteger maxValue)
Generates a BigInteger from the uniform distribution U[0, maxValue-1].java.math.BigInteger
nextBigInteger(java.math.BigInteger minValue, java.math.BigInteger maxValue)
Generates a BigInteger from the uniform distribution U[minValue, maxValue-1].int
nextInt(int minValue, int maxValue)
Creates a random integer from the uniform distribution U[minValue, maxValue-1].java.math.BigDecimal
nextLogDistributedBigDecimal(java.math.BigDecimal minValue, java.math.BigDecimal maxValue, int minScale, int maxScale)
Generates a random BigDecimal from the log-distribution in [minValue, maxValue) that has minScale..maxScale digits after the floating point.java.math.BigInteger
nextLogDistributedBigInteger(java.math.BigInteger maxValue)
Generates a random BigInteger from the log-distribution in [0, maxValue-1].java.math.BigInteger
nextLogDistributedBigInteger(java.math.BigInteger minValue, java.math.BigInteger maxValue)
Generates a random BigInteger from the log-distribution in [minValue, maxValue-1].long
nextLong(long maxValue)
Creates a random long from the uniform distribution U[0, maxValue-1].long
nextLong(long minValue, long maxValue)
Creates a random long from the uniform distribution U[minValue, maxValue-1].Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Rng
public Rng() -
Rng
public Rng(long seed)
-
-
Method Details
-
nextInt
public int nextInt(int minValue, int maxValue)Creates a random integer from the uniform distribution U[minValue, maxValue-1]. Works also for negative arguments; the only requirement is maxValue > minValue.- Parameters:
minValue
-maxValue
-- Returns:
- random int in the desired range
-
nextLong
public long nextLong(long maxValue)Creates a random long from the uniform distribution U[0, maxValue-1]. The only requirement is maxValue > 0.- Parameters:
maxValue
-- Returns:
- random long in the desired range
-
nextLong
public long nextLong(long minValue, long maxValue)Creates a random long from the uniform distribution U[minValue, maxValue-1]. Works also for negative arguments; the only requirement is maxValue > minValue.- Parameters:
minValue
-maxValue
-- Returns:
- random long in the desired range
-
nextBigInteger
public java.math.BigInteger nextBigInteger(java.math.BigInteger maxValue)Generates a BigInteger from the uniform distribution U[0, maxValue-1].- Parameters:
maxValue
- exclusive- Returns:
-
nextBigInteger
public java.math.BigInteger nextBigInteger(java.math.BigInteger minValue, java.math.BigInteger maxValue)Generates a BigInteger from the uniform distribution U[minValue, maxValue-1].- Parameters:
minValue
- inclusivemaxValue
- exclusive- Returns:
-
nextBigInteger
public java.math.BigInteger nextBigInteger(int maxBits)Get uniformly distributed random integer with the specified maximum number of bits, i.e. a number from U[0, 2^maxBits - 1].- Parameters:
maxBits
- size in bits
-
nextLogDistributedBigInteger
public java.math.BigInteger nextLogDistributedBigInteger(java.math.BigInteger maxValue)Generates a random BigInteger from the log-distribution in [0, maxValue-1]. The generation is quite expensive, because it involves exp() and ln() computations.- Parameters:
maxValue
-- Returns:
-
nextLogDistributedBigInteger
public java.math.BigInteger nextLogDistributedBigInteger(java.math.BigInteger minValue, java.math.BigInteger maxValue)Generates a random BigInteger from the log-distribution in [minValue, maxValue-1]. The generation is quite expensive, because it involves exp() and ln() computations.- Parameters:
minValue
-maxValue
-- Returns:
-
nextBigDecimal
public java.math.BigDecimal nextBigDecimal(java.math.BigDecimal maxValue, int resultScale)Generates a BigDecimal from [0, maxValue) with the given number of decimal digits after the floating point.- Parameters:
maxValue
- exclusiveresultScale
-- Returns:
-
nextBigDecimal
public java.math.BigDecimal nextBigDecimal(java.math.BigDecimal maxValue, int minScale, int maxScale)Generates a BigDecimal from U[0, maxValue) with minDigits...maxDigits decimal digits after the floating point.- Parameters:
maxValue
- exclusiveminDigits
-maxDigits
-- Returns:
-
nextBigDecimal
public java.math.BigDecimal nextBigDecimal(java.math.BigDecimal minValue, java.math.BigDecimal maxValue, int minScale, int maxScale)Generates a BigDecimal from U[minValue, maxValue) with minDigits...maxDigits decimal digits after the floating point.- Parameters:
minValue
- inclusivemaxValue
- exclusiveminScale
-maxScale
-- Returns:
-
nextLogDistributedBigDecimal
public java.math.BigDecimal nextLogDistributedBigDecimal(java.math.BigDecimal minValue, java.math.BigDecimal maxValue, int minScale, int maxScale)Generates a random BigDecimal from the log-distribution in [minValue, maxValue) that has minScale..maxScale digits after the floating point. The generation is quite expensive, because it involves exp() and ln() computations.- Parameters:
minValue
-maxValue
-minScale
-maxScale
-- Returns:
-