Package com.atlassian.security.random
Class DefaultSecureRandomService
java.lang.Object
com.atlassian.security.random.DefaultSecureRandomService
- All Implemented Interfaces:
SecureRandomService
Implementation of the
SecureRandomService which delegates to a single, shared instance
of SecureRandom.
Potential improvements include:
- Periodic Re-seeding: currently we are not sure if this is a requirement, so it has not been implemented.
- Object Pooling: as
SecureRandoms block on calls to produce random data, we may improve throughput by pooling a collection ofSecureRandoms. Contention is not yet been proved to be a problem, so it has not been implemented.
The current implementation is guaranteed to be thread-safe as it delegates calls to the
underlying SecureRandom instance.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SecureRandomServicebooleanReturns the next pseudorandomboolean.voidnextBytes(byte[] bytes) Generates a user-specified number of random bytes.doubleReturns the next pseudorandomdouble.floatReturns the next pseudorandomfloat.intnextInt()Returns the next pseudorandomint.intnextInt(int n) Returns a pseudorandom,intvalue between 0 (inclusive) and the specified value (exclusive).longnextLong()Returns the next pseudorandomlong.
-
Method Details
-
getInstance
- Returns:
- shared
DefaultSecureRandomServiceinstance which delegates to a single, shared instance ofSecureRandom.
-
nextBytes
public void nextBytes(byte[] bytes) Description copied from interface:SecureRandomServiceGenerates a user-specified number of random bytes.- Specified by:
nextBytesin interfaceSecureRandomService- Parameters:
bytes- the array to be filled in with random bytes.- See Also:
-
nextInt
public int nextInt()Description copied from interface:SecureRandomServiceReturns the next pseudorandomint.- Specified by:
nextIntin interfaceSecureRandomService- Returns:
- the next pseudorandom
int. - See Also:
-
nextInt
public int nextInt(int n) Description copied from interface:SecureRandomServiceReturns a pseudorandom,intvalue between 0 (inclusive) and the specified value (exclusive).- Specified by:
nextIntin interfaceSecureRandomService- Parameters:
n- the bound on the random number to be returned. Must be positive.- Returns:
- the next pseudorandom,
intvalue between0(inclusive) andn(exclusive). - See Also:
-
nextLong
public long nextLong()Description copied from interface:SecureRandomServiceReturns the next pseudorandomlong.- Specified by:
nextLongin interfaceSecureRandomService- Returns:
- the next pseudorandom
long. - See Also:
-
nextBoolean
public boolean nextBoolean()Description copied from interface:SecureRandomServiceReturns the next pseudorandomboolean.- Specified by:
nextBooleanin interfaceSecureRandomService- Returns:
- the next pseudorandom
boolean. - See Also:
-
nextFloat
public float nextFloat()Description copied from interface:SecureRandomServiceReturns the next pseudorandomfloat.- Specified by:
nextFloatin interfaceSecureRandomService- Returns:
- the next pseudorandom
float. - See Also:
-
nextDouble
public double nextDouble()Description copied from interface:SecureRandomServiceReturns the next pseudorandomdouble.- Specified by:
nextDoublein interfaceSecureRandomService- Returns:
- the next pseudorandom
double. - See Also:
-