Class XORShiftRNG

java.lang.Object
java.util.Random
net.citizensnpcs.util.XORShiftRNG
All Implemented Interfaces:
Serializable, java.util.random.RandomGenerator

public class XORShiftRNG extends Random

Very fast pseudo random number generator. See this page for a description. This RNG has a period of about 2^160, which is not as long as the MersenneTwisterRNG but it is faster.

NOTE: Because instances of this class require 160-bit seeds, it is not possible to seed this RNG using the Random.setSeed(long) method inherited from Random. Calls to this method will have no effect. Instead the seed must be set by a constructor.

Since:
1.2
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
    Creates an RNG and seeds it with the specified seed data.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    convertBytesToInt(byte[] bytes, int offset)
    Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the big-endian convention.
    static int[]
    convertBytesToInts(byte[] bytes)
    Convert an array of bytes into an array of ints.
    byte[]
     
    protected int
    next(int bits)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, 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

    • XORShiftRNG

      public XORShiftRNG()
      Creates an RNG and seeds it with the specified seed data.
  • Method Details

    • getSeed

      public byte[] getSeed()
    • next

      protected int next(int bits)
      Overrides:
      next in class Random
    • convertBytesToInt

      public static int convertBytesToInt(byte[] bytes, int offset)
      Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the big-endian convention.
      Parameters:
      bytes - The data to read from.
      offset - The position to start reading the 4-byte int from.
      Returns:
      The 32-bit integer represented by the four bytes.
    • convertBytesToInts

      public static int[] convertBytesToInts(byte[] bytes)
      Convert an array of bytes into an array of ints. 4 bytes from the input data map to a single int in the output data.
      Parameters:
      bytes - The data to read from.
      Returns:
      An array of 32-bit integers constructed from the data.
      Since:
      1.1