org.owasp.esapi
Class Randomizer

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

public class Randomizer
extends java.lang.Object
implements IRandomizer

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:
IRandomizer

Constructor Summary
Randomizer()
          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

Randomizer

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

Method Detail

getRandomString

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

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

getRandomBoolean

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

Specified by:
getRandomBoolean in interface IRandomizer
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 IRandomizer
Parameters:
min - the min
max - the max
Returns:
the random integer
See Also:
IRandomizer.getRandomInteger(int, int)

getRandomReal

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

Specified by:
getRandomReal in interface IRandomizer
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 IRandomizer

getRandomGUID

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

Specified by:
getRandomGUID in interface IRandomizer
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