org.owasp.esapi.reference
Class DefaultRandomizer

java.lang.Object
  extended byorg.owasp.esapi.reference.DefaultRandomizer
All Implemented Interfaces:
Randomizer

public class DefaultRandomizer
extends java.lang.Object
implements Randomizer

Reference implementation of the IRandomizer interface. This implementation builds on the JCE provider to provide a cryptographically strong source of entropy. The specific algorithm used is configurable in ESAPI.properties.

Since:
June 1, 2007
Author:
Jeff Williams, Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
See Also:
Randomizer

Constructor Summary
DefaultRandomizer()
          Hide the constructor for the Singleton pattern.
 
Method Summary
static boolean contains(java.lang.StringBuffer sb, char c)
          Contains.
 boolean getRandomBoolean()
          Returns a random boolean.
 java.lang.String getRandomFilename(java.lang.String extension)
          Returns an unguessable random filename with the specified extension.
 java.lang.String getRandomGUID()
          Generates a random GUID.
 int getRandomInteger(int min, int max)
          FIXME: ENHANCE document whether this is inclusive or not (non-Javadoc)
 float getRandomReal(float min, float max)
          Gets the random real.
 java.lang.String getRandomString(int length, char[] characterSet)
          Gets the random string.
static char[] union(char[] c1, char[] c2)
          Union two character arrays.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultRandomizer

public DefaultRandomizer()
Hide the constructor for the Singleton pattern.

Method Detail

getRandomString

public java.lang.String getRandomString(int length,
                                        char[] characterSet)
Description copied from interface: Randomizer
Gets the random string.

Specified by:
getRandomString in interface Randomizer
Parameters:
length - the length
characterSet - the character set
Returns:
the random string

getRandomBoolean

public boolean getRandomBoolean()
Description copied from interface: Randomizer
Returns a random boolean.

Specified by:
getRandomBoolean in interface Randomizer
Returns:

getRandomInteger

public int getRandomInteger(int min,
                            int max)
FIXME: ENHANCE document whether this is inclusive or not (non-Javadoc)

Specified by:
getRandomInteger in interface Randomizer
Parameters:
min - the min
max - the max
Returns:
the random integer
See Also:
Randomizer.getRandomInteger(int, int)

getRandomReal

public float getRandomReal(float min,
                           float max)
Description copied from interface: Randomizer
Gets the random real.

Specified by:
getRandomReal in interface Randomizer
Parameters:
min - the min
max - the max
Returns:
the random real

getRandomFilename

public java.lang.String getRandomFilename(java.lang.String extension)
Returns an unguessable random filename with the specified extension.

Specified by:
getRandomFilename in interface Randomizer

getRandomGUID

public java.lang.String getRandomGUID()
                               throws EncryptionException
Description copied from interface: Randomizer
Generates a random GUID.

Specified by:
getRandomGUID in interface Randomizer
Returns:
the GUID
Throws:
EncryptionException

union

public static char[] union(char[] c1,
                           char[] c2)
Union two character arrays.

Parameters:
c1 - the c1
c2 - the c2
Returns:
the char[]

contains

public static boolean contains(java.lang.StringBuffer sb,
                               char c)
Contains.

Parameters:
sb - the sb
c - the c
Returns:
true, if successful