Class SafeThreadLocalRandom
java.lang.Object
java.util.Random
com.palantir.random.SafeThreadLocalRandom
- All Implemented Interfaces:
Serializable, RandomGenerator
An implementation of
Random that delegates all methods to ThreadLocalRandom.current().
This class can be used as a drop in replacement for new Random().
Unlike ThreadLocalRandom, an instance of SafeThreadLocalRandom may be used by multiple threads
because each method invocation delegates to ThreadLocalRandom.current().
Note that because this is a shared instance, Random.setSeed(long) is unsupported.
This is not a SecureRandom instance and must not be used for cryptography.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface RandomGenerator
RandomGenerator.ArbitrarilyJumpableGenerator, RandomGenerator.JumpableGenerator, RandomGenerator.LeapableGenerator, RandomGenerator.SplittableGenerator, RandomGenerator.StreamableGenerator -
Method Summary
Modifier and TypeMethodDescriptiondoubles()doubles(double randomNumberOrigin, double randomNumberBound) doubles(long streamSize) doubles(long streamSize, double randomNumberOrigin, double randomNumberBound) static Randomget()Gets the singletonSafeThreadLocalRandominstance.ints()ints(int randomNumberOrigin, int randomNumberBound) ints(long streamSize) ints(long streamSize, int randomNumberOrigin, int randomNumberBound) longs()longs(long streamSize) longs(long randomNumberOrigin, long randomNumberBound) longs(long streamSize, long randomNumberOrigin, long randomNumberBound) protected intnext(int _bits) booleanvoidnextBytes(byte[] bytes) doublefloatdoubleintnextInt()intnextInt(int bound) longnextLong()voidsetSeed(long _seed) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface RandomGenerator
equiDoubles, isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
Method Details
-
get
Gets the singletonSafeThreadLocalRandominstance. -
setSeed
-
next
-
nextBytes
public void nextBytes(byte[] bytes) - Specified by:
nextBytesin interfaceRandomGenerator- Overrides:
nextBytesin classRandom
-
nextInt
public int nextInt()- Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextInt
public int nextInt(int bound) - Specified by:
nextIntin interfaceRandomGenerator- Overrides:
nextIntin classRandom
-
nextLong
public long nextLong()- Specified by:
nextLongin interfaceRandomGenerator- Overrides:
nextLongin classRandom
-
nextBoolean
public boolean nextBoolean()- Specified by:
nextBooleanin interfaceRandomGenerator- Overrides:
nextBooleanin classRandom
-
nextFloat
public float nextFloat()- Specified by:
nextFloatin interfaceRandomGenerator- Overrides:
nextFloatin classRandom
-
nextDouble
public double nextDouble()- Specified by:
nextDoublein interfaceRandomGenerator- Overrides:
nextDoublein classRandom
-
nextGaussian
public double nextGaussian()- Specified by:
nextGaussianin interfaceRandomGenerator- Overrides:
nextGaussianin classRandom
-
ints
- Specified by:
intsin interfaceRandomGenerator- Overrides:
intsin classRandom
-
ints
- Specified by:
intsin interfaceRandomGenerator- Overrides:
intsin classRandom
-
ints
- Specified by:
intsin interfaceRandomGenerator- Overrides:
intsin classRandom
-
ints
- Specified by:
intsin interfaceRandomGenerator- Overrides:
intsin classRandom
-
longs
- Specified by:
longsin interfaceRandomGenerator- Overrides:
longsin classRandom
-
longs
- Specified by:
longsin interfaceRandomGenerator- Overrides:
longsin classRandom
-
longs
- Specified by:
longsin interfaceRandomGenerator- Overrides:
longsin classRandom
-
longs
- Specified by:
longsin interfaceRandomGenerator- Overrides:
longsin classRandom
-
doubles
- Specified by:
doublesin interfaceRandomGenerator- Overrides:
doublesin classRandom
-
doubles
- Specified by:
doublesin interfaceRandomGenerator- Overrides:
doublesin classRandom
-
doubles
- Specified by:
doublesin interfaceRandomGenerator- Overrides:
doublesin classRandom
-
doubles
- Specified by:
doublesin interfaceRandomGenerator- Overrides:
doublesin classRandom
-
toString
-