com.atlassian.security.random
Class DefaultSecureRandomService

java.lang.Object
  extended by com.atlassian.security.random.DefaultSecureRandomService
All Implemented Interfaces:
SecureRandomService

public final class DefaultSecureRandomService
extends Object
implements SecureRandomService

Implementation of the SecureRandomService which delegates to a single, shared instance of SecureRandom.

Potential improvements include:

The current implementation is guaranteed to be thread-safe as it delegates calls to the underlying SecureRandom instance.


Method Summary
static SecureRandomService getInstance()
           
 boolean nextBoolean()
          Returns the next pseudorandom boolean.
 void nextBytes(byte[] bytes)
          Generates a user-specified number of random bytes.
 double nextDouble()
          Returns the next pseudorandom double.
 float nextFloat()
          Returns the next pseudorandom float.
 int nextInt()
          Returns the next pseudorandom int.
 int nextInt(int n)
          Returns a pseudorandom, int value between 0 (inclusive) and the specified value (exclusive).
 long nextLong()
          Returns the next pseudorandom long.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SecureRandomService getInstance()
Returns:
shared DefaultSecureRandomService instance which delegates to a single, shared instance of SecureRandom.

nextBytes

public void nextBytes(byte[] bytes)
Description copied from interface: SecureRandomService
Generates a user-specified number of random bytes.

Specified by:
nextBytes in interface SecureRandomService
Parameters:
bytes - the array to be filled in with random bytes.
See Also:
SecureRandom.nextBytes(byte[])

nextInt

public int nextInt()
Description copied from interface: SecureRandomService
Returns the next pseudorandom int.

Specified by:
nextInt in interface SecureRandomService
Returns:
the next pseudorandom int.
See Also:
Random.nextInt()

nextInt

public int nextInt(int n)
Description copied from interface: SecureRandomService
Returns a pseudorandom, int value between 0 (inclusive) and the specified value (exclusive).

Specified by:
nextInt in interface SecureRandomService
Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
the next pseudorandom, int value between 0 (inclusive) and n (exclusive).
See Also:
Random.nextInt(int)

nextLong

public long nextLong()
Description copied from interface: SecureRandomService
Returns the next pseudorandom long.

Specified by:
nextLong in interface SecureRandomService
Returns:
the next pseudorandom long.
See Also:
Random.nextLong()

nextBoolean

public boolean nextBoolean()
Description copied from interface: SecureRandomService
Returns the next pseudorandom boolean.

Specified by:
nextBoolean in interface SecureRandomService
Returns:
the next pseudorandom boolean.
See Also:
Random.nextBoolean()

nextFloat

public float nextFloat()
Description copied from interface: SecureRandomService
Returns the next pseudorandom float.

Specified by:
nextFloat in interface SecureRandomService
Returns:
the next pseudorandom float.
See Also:
Random.nextFloat()

nextDouble

public double nextDouble()
Description copied from interface: SecureRandomService
Returns the next pseudorandom double.

Specified by:
nextDouble in interface SecureRandomService
Returns:
the next pseudorandom double.
See Also:
Random.nextDouble()


Copyright © 2013 Atlassian. All rights reserved.