Event Dispatcher  v0.1.6-beta.1
Project that offers a small library that allows to subscribe and fire events.
RandomString

Detailed Description

A class to generate pseudorandom sequences of strings.

Definition at line 11 of file RandomString.java.

Public Member Functions

 RandomString (int length, Random random, String symbols)
 
 RandomString (int length, Random random)
 
 RandomString (int length, String symbols)
 
 RandomString (int length)
 
String nextString ()
 

Static Public Attributes

static final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 
static final String LOWER = UPPER.toLowerCase(Locale.ROOT)
 
static final String DIGITS = "0123456789"
 
static final String ALPHANUM = UPPER + LOWER + DIGITS
 

Private Attributes

final Random random
 
final char [] symbols
 
final char [] buffer
 

Constructor & Destructor Documentation

◆ RandomString() [1/4]

RandomString ( int  length,
Random  random,
String  symbols 
)

Constructs a new random string generator instance used to create pseudorandom strings.

Parameters
lengththe random generated string size
randomthe class instance to generate pseudorandom strings
symbolsthe string containing all the symbols, that the random strings will be composed of

Definition at line 29 of file RandomString.java.

◆ RandomString() [2/4]

RandomString ( int  length,
Random  random 
)

Constructs a new random string generator instance.

The random string will be formed with alphanumeric characters.

Parameters
lengththe random generated string size
randomthe class instance to generate pseudorandom strings

Definition at line 49 of file RandomString.java.

◆ RandomString() [3/4]

RandomString ( int  length,
String  symbols 
)

Constructs a new random string generator instance used to create pseudorandom strings from a secure generator.

Parameters
lengththe random generated string size
symbolsthe string containing all the symbols, that the random strings will be composed of

Definition at line 59 of file RandomString.java.

◆ RandomString() [4/4]

RandomString ( int  length)

Constructs a new random string generator instance used to create pseudorandom strings from a secure generator.

The random string will be formed with alphanumeric characters.

Parameters
lengththe random generated string size
See also
SecureRandom

Definition at line 71 of file RandomString.java.

Member Function Documentation

◆ nextString()

String nextString ( )

Returns a pseudorandom, uniformly distributed.

String

value, from this random string generator's sequence. The general contract of

is that one

String

value formed with the available symbols is pseudorandomly generated and returned. All possible

String

values are produced with (approximately) equal probability. The method

is implemented using the provided

Random

class's methods.

The probability of a collision,

p

, is approximately n2/(2qx), where

n

is the number of identifiers actually generated,

q

is the number of distinct symbols in the alphabet, and

x

is the length of the generated string. The longer the

String

is, the lower the probability of a collision taking place is.

Returns
the next pseudorandom, uniformly distributed
String
value formed with the provided symbols and from this random generator's sequence
See also
Random

Definition at line 92 of file RandomString.java.

Member Data Documentation

◆ UPPER

final String UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static

Definition at line 13 of file RandomString.java.

◆ LOWER

final String LOWER = UPPER.toLowerCase(Locale.ROOT)
static

Definition at line 14 of file RandomString.java.

◆ DIGITS

final String DIGITS = "0123456789"
static

Definition at line 15 of file RandomString.java.

◆ ALPHANUM

final String ALPHANUM = UPPER + LOWER + DIGITS
static

Definition at line 16 of file RandomString.java.

◆ random

final Random random
private

Definition at line 18 of file RandomString.java.

◆ symbols

final char [] symbols
private

Definition at line 19 of file RandomString.java.

◆ buffer

final char [] buffer
private

Definition at line 20 of file RandomString.java.