Class PcgRSLocked

  • All Implemented Interfaces:
    Pcg, java.io.Serializable

    public class PcgRSLocked
    extends RandomBaseLocked
    A 64 bit State PcgRNG with 32 bit output. PCG-XSH-RR

    The pcg family combines a linear congruential generators with a permutation output function resulting in high quality pseudo random numbers.

    The original concept was introduced by Melissa O’Neill please refer to pcg-random for more information.

    Opposed to RR this version performs a random shift rather than a random rotation. The RS instance permutates the output using the following function:

     
     ((state >>> 22) ^ state) >>> ((state >>> 61) + 22)
     
     
    This implementation is thread safe utilizing read write locks. During non contested periods this version performs considerably slower and only gains the upper hand if the synchronized parts are hammered consistently.
    Author:
    Kilian
    See Also:
    www.pcg-random.org, Serialized Form
    • Constructor Detail

      • PcgRSLocked

        public PcgRSLocked()
        Create a synchronized PcgRS instance seeded with with 2 longs generated by xorshift*. The values chosen are very likely not used as seeds in any other non argument constructor of any of the classes provided in this library.
      • PcgRSLocked

        public PcgRSLocked​(long seed,
                           long streamNumber)
        Create a random number generator with the given seed and stream number. The seed defines the current state in which the rng is in and corresponds to seeds usually found in other RNG implementations. RNGs with different seeds are able to catch up after they exhaust their period and produce the same numbers.

        Different stream numbers alter the increment of the rng and ensure distinct state sequences

        Only generators with the same seed AND stream numbers will produce identical values

        Parameters:
        seed - used to compute the starting state of the RNG
        streamNumber - used to compute the increment for the lcg.
      • PcgRSLocked

        @Deprecated
        public PcgRSLocked​(long seed,
                           long streamNumber,
                           boolean dummy)
        Deprecated.
        Copy constructor. Has to be implemented in all inheriting instances. This will be invoked through reflection! when calling RandomBase64.split() or RandomBase64.splitDistinct() If no special behavior is desired simply pass though the values. This constructor should usually not be called manually as the seed and increment will just be set without performing any randomization.
        Parameters:
        seed - of the lcg. The value will be set and not altered.
        streamNumber - used in the lcg as increment constant.
        dummy - unused. Resolve signature disambiguate
    • Method Detail

      • getInt

        protected int getInt​(long state)
        Description copied from class: RandomBase64
        Construct a 32bit int from the given 64bit state using a permutation function. The produced int will be used to construct all other datatypes returned by this RNG.
        Specified by:
        getInt in class RandomBase64
        Parameters:
        state - random int as produced by the internal lcg
        Returns:
        a random int with randomly set bits