Class JVMRandom

java.lang.Object
java.util.Random
org.apache.commons.lang.math.JVMRandom
All Implemented Interfaces:
Serializable, java.util.random.RandomGenerator

@Deprecated(since="2021-04-30") public final class JVMRandom extends Random
Deprecated.
Commons Lang 2 is in maintenance mode. Commons Lang 3 should be used instead.

JVMRandom is a wrapper that supports all possible Random methods via the Math.random() method and its system-wide Random object.

It does this to allow for a Random class in which the seed is shared between all members of the class - a better name would have been SharedSeedRandom.

N.B. the current implementation overrides the methods Random.nextInt(int) and Random.nextLong() to produce positive numbers ranging from 0 (inclusive) to MAX_VALUE (exclusive).

Since:
2.0
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface java.util.random.RandomGenerator

    java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.SplittableGenerator, java.util.random.RandomGenerator.StreamableGenerator
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
    Constructs a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Deprecated.
    Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.
    void
    nextBytes(byte[] byteArray)
    Deprecated.
    Unsupported in 2.0.
    double
    Deprecated.
    Synonymous to the Math.random() call.
    float
    Deprecated.
    Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from the Math.random() sequence.
    double
    Deprecated.
    Unsupported in 2.0.
    int
    Deprecated.
    Returns the next pseudorandom, uniformly distributed int value from the Math.random() sequence.
    int
    nextInt(int n)
    Deprecated.
    Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), from the Math.random() sequence.
    long
    Deprecated.
    Returns the next pseudorandom, uniformly distributed long value from the Math.random() sequence.
    static long
    nextLong(long n)
    Deprecated.
    Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), from the Math.random() sequence.
    void
    setSeed(long seed)
    Deprecated.
    Unsupported in 2.0.

    Methods inherited from class java.util.Random

    doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.random.RandomGenerator

    isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
  • Constructor Details

    • JVMRandom

      public JVMRandom()
      Deprecated.
      Constructs a new instance.
  • Method Details

    • setSeed

      public void setSeed(long seed)
      Deprecated.
      Unsupported in 2.0.
      Overrides:
      setSeed in class Random
      Parameters:
      seed - ignored
      Throws:
      UnsupportedOperationException
    • nextGaussian

      public double nextGaussian()
      Deprecated.
      Unsupported in 2.0.
      Specified by:
      nextGaussian in interface java.util.random.RandomGenerator
      Overrides:
      nextGaussian in class Random
      Returns:
      Nothing, this method always throws an UnsupportedOperationException.
      Throws:
      UnsupportedOperationException
    • nextBytes

      public void nextBytes(byte[] byteArray)
      Deprecated.
      Unsupported in 2.0.
      Specified by:
      nextBytes in interface java.util.random.RandomGenerator
      Overrides:
      nextBytes in class Random
      Parameters:
      byteArray - ignored
      Throws:
      UnsupportedOperationException
    • nextInt

      public int nextInt()
      Deprecated.

      Returns the next pseudorandom, uniformly distributed int value from the Math.random() sequence.

      Identical to nextInt(Integer.MAX_VALUE)

      N.B. All values are >= 0.

      Specified by:
      nextInt in interface java.util.random.RandomGenerator
      Overrides:
      nextInt in class Random
      Returns:
      the random int
    • nextInt

      public int nextInt(int n)
      Deprecated.

      Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), from the Math.random() sequence.

      Specified by:
      nextInt in interface java.util.random.RandomGenerator
      Overrides:
      nextInt in class Random
      Parameters:
      n - the specified exclusive max-value
      Returns:
      the random int
      Throws:
      IllegalArgumentException - when n <= 0
    • nextLong

      public long nextLong()
      Deprecated.

      Returns the next pseudorandom, uniformly distributed long value from the Math.random() sequence.

      Identical to nextLong(Long.MAX_VALUE)

      N.B. All values are >= 0.

      Specified by:
      nextLong in interface java.util.random.RandomGenerator
      Overrides:
      nextLong in class Random
      Returns:
      the random long
    • nextLong

      public static long nextLong(long n)
      Deprecated.

      Returns a pseudorandom, uniformly distributed long value between 0 (inclusive) and the specified value (exclusive), from the Math.random() sequence.

      Parameters:
      n - the specified exclusive max-value
      Returns:
      the random long
      Throws:
      IllegalArgumentException - when n <= 0
    • nextBoolean

      public boolean nextBoolean()
      Deprecated.

      Returns the next pseudorandom, uniformly distributed boolean value from the Math.random() sequence.

      Specified by:
      nextBoolean in interface java.util.random.RandomGenerator
      Overrides:
      nextBoolean in class Random
      Returns:
      the random boolean
    • nextFloat

      public float nextFloat()
      Deprecated.

      Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from the Math.random() sequence.

      Specified by:
      nextFloat in interface java.util.random.RandomGenerator
      Overrides:
      nextFloat in class Random
      Returns:
      the random float
    • nextDouble

      public double nextDouble()
      Deprecated.

      Synonymous to the Math.random() call.

      Specified by:
      nextDouble in interface java.util.random.RandomGenerator
      Overrides:
      nextDouble in class Random
      Returns:
      the random double