Package com.github.kilianB.pcg.sync
Class PcgRR
- java.lang.Object
-
- java.util.Random
-
- com.github.kilianB.pcg.RandomBase64
-
- com.github.kilianB.pcg.sync.RandomBaseSynchonized
-
- com.github.kilianB.pcg.sync.PcgRR
-
- All Implemented Interfaces:
Pcg,java.io.Serializable
public class PcgRR extends RandomBaseSynchonized
A 64 bit State PcgRNG with 32 bit output. PCG-XSH-RRThe 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.
The RR instance permutates the output using the following function:
Regarding the RR Instance: "[...The] design goal is to be a good all-purpose random number generator. The intent is to balance speed with statistical performance and reasonable security, charting a middle-of-the-road path. (It’s the generator that I recommend for most users.) The strategy is to perform an xorshift to improve the high bits, then randomly rotate them so that all bits are full period. Hence the mnemonic PCG-XSH-RR, “xorshift high (bits), random rotation”." This implementation is thread safe utilizing method level synchronization.int shift = (int) (((state >>> 18) ^ state) >>> 27); int rotation = (int) (state >>> 59); return Integer.rotateRight(shift, rotation);- Author:
- Kilian
- See Also:
- www.pcg-random.org,
PcgRS, Serialized Form
-
-
Field Summary
-
Fields inherited from class com.github.kilianB.pcg.sync.RandomBaseSynchonized
inc, state
-
Fields inherited from class com.github.kilianB.pcg.RandomBase64
MULT_64
-
Fields inherited from interface com.github.kilianB.pcg.Pcg
UNIQUE_SEED
-
-
Constructor Summary
Constructors Constructor Description PcgRR()Create a synchronized PcgRR instance seeded with with 2 longs generated by xorshift*.PcgRR(long seed, long streamNumber)Create a random number generator with the given seed and stream number.PcgRR(long seed, long streamNumber, boolean dummy)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intgetInt(long state)Construct a 32bit int from the given 64bit state using a permutation function.-
Methods inherited from class com.github.kilianB.pcg.sync.RandomBaseSynchonized
advance, distanceUnsafe, getInc, getState, isFast, setInc, setState, split, splitDistinct, stepRight
-
Methods inherited from class com.github.kilianB.pcg.RandomBase64
getMult, getRandomSeed, next, nextBoolean, nextByte, nextBytes, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextLong, nextShort, setSeed, setSeed
-
Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.kilianB.pcg.Pcg
distance, nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt
-
-
-
-
Constructor Detail
-
PcgRR
public PcgRR()
Create a synchronized PcgRR 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.
-
PcgRR
public PcgRR(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 RNGstreamNumber- used to compute the increment for the lcg.
-
PcgRR
@Deprecated public PcgRR(long seed, long streamNumber, boolean dummy)Deprecated.Copy constructor. Has to be implemented in all inheriting instances. This will be invoked through reflection! when callingRandomBaseSynchonized.split()orRandomBaseSynchonized.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:RandomBase64Construct 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:
getIntin classRandomBase64- Parameters:
state- random int as produced by the internal lcg- Returns:
- a random int with randomly set bits
-
-