org.apache.commons.lang
Class RandomStringUtils

java.lang.Object
  |
  +--org.apache.commons.lang.RandomStringUtils

public class RandomStringUtils
extends java.lang.Object

Common random String manipulation routines.

Originally from the GenerationJava Core library.

Version:
$Id: RandomStringUtils.java,v 1.5 2002/09/28 10:34:54 scolebourne Exp $
Author:
Henri Yandell, Steven Caswell, Stephen Colebourne

Field Summary
private static java.util.Random RANDOM
          Random object used by random method.
 
Constructor Summary
RandomStringUtils()
          RandomStringUtils instances should NOT be constructed in standard programming.
 
Method Summary
static java.lang.String random(int count)
          Creates a random string whose length is the number of characters specified.
static java.lang.String random(int count, boolean letters, boolean numbers)
          Creates a random string whose length is the number of characters specified.
static java.lang.String random(int count, char[] set)
          Creates a random string whose length is the number of characters specified.
static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers)
          Creates a random string whose length is the number of characters specified.
static java.lang.String random(int count, int start, int end, boolean letters, boolean numbers, char[] set)
          Creates a random string based on a variety of options.
static java.lang.String random(int count, java.lang.String set)
          Creates a random string whose length is the number of characters specified.
static java.lang.String randomAlphabetic(int count)
          Creates a random string whose length is the number of characters specified.
static java.lang.String randomAlphanumeric(int count)
          Creates a random string whose length is the number of characters specified.
static java.lang.String randomAscii(int count)
          Creates a random string whose length is the number of characters specified.
static java.lang.String randomNumeric(int count)
          Creates a random string whose length is the number of characters specified.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

RANDOM

private static final java.util.Random RANDOM
Random object used by random method. This has to be not local to the random method so as to not return the same value in the same millisecond.
Constructor Detail

RandomStringUtils

public RandomStringUtils()
RandomStringUtils instances should NOT be constructed in standard programming. Instead, the class should be used as RandomStringUtils.random(5);. This constructor is public to permit tools that require a JavaBean instance to operate.
Method Detail

random

public static java.lang.String random(int count)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of all characters.
Parameters:
count - length of random string to create
Returns:
the random string

randomAscii

public static java.lang.String randomAscii(int count)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of characters whose ASCII value is between 32 and 127 .
Parameters:
count - length of random string to create
Returns:
the random string

randomAlphabetic

public static java.lang.String randomAlphabetic(int count)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alphabetic characters.
Parameters:
count - length of random string to create
Returns:
the random string

randomAlphanumeric

public static java.lang.String randomAlphanumeric(int count)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alpha-numeric characters.
Parameters:
count - length of random string to create
Returns:
the random string

randomNumeric

public static java.lang.String randomNumeric(int count)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of numeric characters.
Parameters:
count - length of random string to create
Returns:
the random string

random

public static java.lang.String random(int count,
                                      boolean letters,
                                      boolean numbers)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.
Parameters:
count - length of random string to create
letters - if true, generated string will include alphabetic characters
numbers - if true, generatd string will include numeric characters
Returns:
the random string

random

public static java.lang.String random(int count,
                                      int start,
                                      int end,
                                      boolean letters,
                                      boolean numbers)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of alpha-numeric characters as indicated by the arguments.
Parameters:
count - length of random string to create
start - int position in set of chars to start at
end - int position in set of chars to end before
letters - if true, generated string will include alphabetic characters
numbers - if true, generatd string will include numeric characters
Returns:
the random string

random

public static java.lang.String random(int count,
                                      int start,
                                      int end,
                                      boolean letters,
                                      boolean numbers,
                                      char[] set)
Creates a random string based on a variety of options. If start and end are both 0, start and end are set to ' ' and 'z', the ASCII printable characters, will be used, unless letters and numbers are both false, in which case, start and end are set to 0 and Integer.MAX_VALUE.

If set is not null, characters between start and end are chosen.

Parameters:
count - int length of random string to create
start - int position in set of chars to start at
end - int position in set of chars to end before
letters - boolean only allow letters?
numbers - boolean only allow numbers?
set - char[] set of chars to choose randoms from. If null, then it will use the set of all chars.
Returns:
the random string
Throws:
ArrayIndexOutOfBoundsException - if there are not (end - start) + 1 characters in the set array.

random

public static java.lang.String random(int count,
                                      java.lang.String set)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of characters specified.
Parameters:
count - int length of random string to create
set - String containing the set of characters to use
Returns:
the random string

random

public static java.lang.String random(int count,
                                      char[] set)
Creates a random string whose length is the number of characters specified. Characters will be chosen from the set of characters specified.
Parameters:
count - int length of random string to create
set - character array containing the set of characters to use
Returns:
the random string


Copyright (c) 2001-2002 - Apache Software Foundation