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 TypeMethodDescriptionboolean
Returns the next pseudorandom, uniformly distributedboolean
value from this random number generator's sequence.boolean
nextBoolean
(double probability) byte
nextByte()
void
nextBytes
(byte[] b) char
nextChar()
double
double
nextDouble
(boolean includeZero, boolean includeOne) float
float
nextFloat
(boolean includeZero, boolean includeOne) int
nextInt()
Returns the next pseudorandom, uniformly distributedint
value from this random number generator's sequence.int
nextInt
(int n) Returns a pseudorandom, uniformly distributedint
value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.long
nextLong()
long
nextLong
(long n) short
void
setSeed
(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 distributedint
value from this random number generator's sequence. The general contract ofnextInt
is that oneint
value is pseudorandomly generated and returned. All 232 possibleint
values are produced with (approximately) equal probability.- Returns:
- the next pseudorandom, uniformly distributed
int
value from this random number generator's sequence
-
nextInt
public int nextInt(int n) Returns a pseudorandom, uniformly distributedint
value 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
int
value between zero (inclusive) andbound
(exclusive) from this random number generator's sequence
-
nextBoolean
public boolean nextBoolean()Returns the next pseudorandom, uniformly distributedboolean
value from this random number generator's sequence. The general contract ofnextBoolean
is that oneboolean
value is pseudorandomly generated and returned. The valuestrue
andfalse
are produced with (approximately) equal probability.- Returns:
- the next pseudorandom, uniformly distributed
boolean
value 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)
-