Package io.sentry.util
Class Random
java.lang.Object
io.sentry.util.Random
- All Implemented Interfaces:
Serializable
A simplified replacement for
Random, based on pcg-java that we use for
sampling, which is much faster than SecureRandom. This is necessary so that
some security tools do not flag our Random usage as potentially insecure.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence.booleannextBoolean(double probability) bytenextByte()voidnextBytes(byte[] b) charnextChar()doubledoublenextDouble(boolean includeZero, boolean includeOne) floatfloatnextFloat(boolean includeZero, boolean includeOne) intnextInt()Returns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence.intnextInt(int n) Returns a pseudorandom, uniformly distributedintvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.longnextLong()longnextLong(long n) shortvoidsetSeed(long seed, long streamNumber) Sets the seed of this random number generator using .
-
Constructor Details
-
Random
public Random()Create a PcgRSFast 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. -
Random
public Random(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 instances. RNGs with different seeds are able to catch up after they exhaust their period and produce the same numbers. (2^63).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.
-
-
Method Details
-
setSeed
public void setSeed(long seed, long streamNumber) Sets the seed of this random number generator using . The general contract of setSeed is that it alters the state of this random number generator object so as to be in exactly the same state as if it had just been created with the argument seed as a seed.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.
-
nextByte
public byte nextByte() -
nextBytes
public void nextBytes(byte[] b) -
nextChar
public char nextChar() -
nextShort
public short nextShort() -
nextInt
public int nextInt()Returns the next pseudorandom, uniformly distributedintvalue from this random number generator's sequence. The general contract ofnextIntis that oneintvalue is pseudorandomly generated and returned. All 232 possibleintvalues are produced with (approximately) equal probability.- Returns:
- the next pseudorandom, uniformly distributed
intvalue from this random number generator's sequence
-
nextInt
public int nextInt(int n) Returns a pseudorandom, uniformly distributedintvalue between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.- Parameters:
n- the upper bound (exclusive). Must be positive.- Returns:
- the next pseudorandom, uniformly distributed
intvalue between zero (inclusive) andbound(exclusive) from this random number generator's sequence
-
nextBoolean
public boolean nextBoolean()Returns the next pseudorandom, uniformly distributedbooleanvalue from this random number generator's sequence. The general contract ofnextBooleanis that onebooleanvalue is pseudorandomly generated and returned. The valuestrueandfalseare produced with (approximately) equal probability.- Returns:
- the next pseudorandom, uniformly distributed
booleanvalue from this random number generator's sequence
-
nextBoolean
public boolean nextBoolean(double probability) -
nextLong
public long nextLong() -
nextLong
public long nextLong(long n) -
nextDouble
public double nextDouble() -
nextDouble
public double nextDouble(boolean includeZero, boolean includeOne) -
nextFloat
public float nextFloat() -
nextFloat
public float nextFloat(boolean includeZero, boolean includeOne)
-