Class XORShiftRandom

  • All Implemented Interfaces:
    Serializable

    @Public
    public class XORShiftRandom
    extends Random
    Implement a random number generator based on the XORShift algorithm discovered by George Marsaglia. This RNG is observed 4.5 times faster than Random in benchmark, with the cost that abandon thread-safety. So it's recommended to create a new XORShiftRandom for each thread.
    See Also:
    XORShift Algorithm Paper, Serialized Form
    • Constructor Detail

      • XORShiftRandom

        public XORShiftRandom()
      • XORShiftRandom

        public XORShiftRandom​(long input)
    • Method Detail

      • next

        public int next​(int bits)
        All other methods like nextInt()/nextDouble()... depends on this, so we just need to overwrite this.
        Overrides:
        next in class Random
        Parameters:
        bits - Random bits
        Returns:
        The next pseudorandom value from this random number generator's sequence