Class AlternateRandom

java.lang.Object
java.util.Random
com.github.tommyettinger.digital.AlternateRandom
All Implemented Interfaces:
Serializable, RandomGenerator

public class AlternateRandom extends Random
A drop-in replacement for Random that adds no new APIs, but is faster, has better statistical quality, and has a guaranteed longer minimum period (also called cycle length). This is similar to PasarRandom in the Juniper library, and uses the same algorithm, but only extends Random, not Juniper's EnhancedRandom class. If you depend on Juniper, you lose nothing from using the EnhancedRandom classes (they also extend Random), but this class doesn't have as many features as Juniper's PasarRandom. AlternateRandom doesn't depend on anything outside the JDK, though, so it fits easily as a small addition into digital.
This is mostly here to speed up the default shuffling methods in ArrayTools, and to allow those to produce many more possible shuffles. The number of possible shuffles that can be produced by that type of algorithm depends on the number of possible states of the random number generator; that number here is 2 to the 320, or 2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576 (but the actual amount in practice is smaller, to a hard minimum of 2 to the 64, or 18446744073709551616).
See Also:
  • Constructor Details

    • AlternateRandom

      public AlternateRandom()
      Creates a new AlternateRandom with a random state.
    • AlternateRandom

      public AlternateRandom(long seed)
      Creates a new AlternateRandom with the given seed; all long values are permitted. The seed will be passed to setSeed(long) to attempt to adequately distribute the seed randomly.
      Parameters:
      seed - any long value
  • Method Details