Class Xoroshiro128NonThreadsafeRandom

  • All Implemented Interfaces:
    java.io.Serializable

    @Reference(authors="D. Blackman, S. Vigna",
               title="xoroshiro+ / xorshift* / xorshift+ generators and the PRNG shootout",
               booktitle="Online",
               url="http://xoroshiro.di.unimi.it/",
               bibkey="web/BlackmanV16")
    public class Xoroshiro128NonThreadsafeRandom
    extends java.util.Random
    Replacement for Java's Random class, using a different random number generation strategy. Java's random generator is optimized for speed, but may lack the randomness needed for more complex experiments.

    This approach is based on the work on Xoroshiro128+ by Sebastiano Vigna, with the original copyright statement:

    Written in 2016 by David Blackman and Sebastiano Vigna (vigna@acm.org)

    To the extent possible under law, the author has dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

    See http://creativecommons.org/publicdomain/zero/1.0/

    Since:
    0.7.5
    Author:
    Erich Schubert
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.lang.String BADBOUND  
      private long s0
      State of random number generator.
      private long s1
      State of random number generator.
      private static long serialVersionUID
      Serial version number.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected int next​(int bits)  
      double nextDouble()  
      int nextInt()  
      int nextInt​(int n)
      Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
      long nextLong()  
      void setSeed​(long seed)  
      • Methods inherited from class java.util.Random

        doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextBytes, nextFloat, nextGaussian
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Serial version number.
        See Also:
        Constant Field Values
      • s0

        private long s0
        State of random number generator.
      • s1

        private long s1
        State of random number generator.
    • Constructor Detail

      • Xoroshiro128NonThreadsafeRandom

        public Xoroshiro128NonThreadsafeRandom()
        Constructor called only by localRandom.initialValue.
      • Xoroshiro128NonThreadsafeRandom

        public Xoroshiro128NonThreadsafeRandom​(long seed)
        Constructor.
        Parameters:
        seed - Random generator seed.
    • Method Detail

      • setSeed

        public void setSeed​(long seed)
        Overrides:
        setSeed in class java.util.Random
      • nextLong

        public long nextLong()
        Overrides:
        nextLong in class java.util.Random
      • next

        protected int next​(int bits)
        Overrides:
        next in class java.util.Random
      • nextInt

        public int nextInt()
        Overrides:
        nextInt in class java.util.Random
      • nextDouble

        public double nextDouble()
        Overrides:
        nextDouble in class java.util.Random
      • nextInt

        @Reference(authors="D. Lemire",
                   title="Fast random shuffling",
                   booktitle="Daniel Lemire\'s blog",
                   url="http://lemire.me/blog/2016/06/30/fast-random-shuffling/",
                   bibkey="blog/Lemire16")
        public int nextInt​(int n)
        Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. The general contract of nextInt is that one int value in the specified range is pseudorandomly generated and returned. All n possible int values are produced with (approximately) equal probability.

        In contrast to the Java version, we use an approach that tries to avoid divisions for performance discussed in:

        D. Lemire
        Fast random shuffling
        http://lemire.me/blog/2016/06/30/fast-random-shuffling/

        Overrides:
        nextInt in class java.util.Random