Random
Table of Contents
Constants
- ALPHABET_ALL = 15
- ALPHABET_ALPHALOWER = 2
- ALPHABET_ALPHAUPPER = 4
- ALPHABET_NUM = 1
- ALPHABET_SPECIAL = 8
- RANDOM_BLOCK_LENGTH = 64
Methods
- getBytes() : string
- Returns random (if possible) byte string
- getInt() : int
- Returns random integer with the given range
- getString() : string
- Returns random (if possible) alphanum string
- getStringByAlphabet() : string
- Returns random (if possible) ASCII string for a given alphabet mask (@see self::ALPHABET_ALL)
- getStringByArray() : string
- This function places chars from every charset into the result string randomly.
- getStringByCharsets() : string
- Returns random (if possible) string for a given charset list.
Constants
ALPHABET_ALL
public
mixed
ALPHABET_ALL
= 15
ALPHABET_ALPHALOWER
public
mixed
ALPHABET_ALPHALOWER
= 2
ALPHABET_ALPHAUPPER
public
mixed
ALPHABET_ALPHAUPPER
= 4
ALPHABET_NUM
public
mixed
ALPHABET_NUM
= 1
ALPHABET_SPECIAL
public
mixed
ALPHABET_SPECIAL
= 8
RANDOM_BLOCK_LENGTH
public
mixed
RANDOM_BLOCK_LENGTH
= 64
Methods
getBytes()
Returns random (if possible) byte string
public
static getBytes(int $length) : string
Parameters
- $length : int
-
Result byte string length.
Return values
stringgetInt()
Returns random integer with the given range
public
static getInt([int $min = 0 ][, int $max = PHP_INT_MAX ]) : int
Parameters
- $min : int = 0
-
The lower bound of the range.
- $max : int = PHP_INT_MAX
-
The upper bound of the range.
Tags
Return values
intgetString()
Returns random (if possible) alphanum string
public
static getString(int $length[, bool $caseSensitive = false ]) : string
Parameters
- $length : int
-
Result string length.
- $caseSensitive : bool = false
-
Generate case sensitive random string (e.g.
SoMeRandom1
).
Return values
stringgetStringByAlphabet()
Returns random (if possible) ASCII string for a given alphabet mask (@see self::ALPHABET_ALL)
public
static getStringByAlphabet(int $length, int $alphabet[, bool $requireAll = false ]) : string
Parameters
- $length : int
-
Result string length.
- $alphabet : int
-
Alphabet masks (e.g. Random::ALPHABET_NUM|Random::ALPHABET_ALPHALOWER).
- $requireAll : bool = false
-
Required chars from all the alphabet masks.
Return values
stringgetStringByArray()
This function places chars from every charset into the result string randomly.
public
static getStringByArray(int $length, array<string|int, mixed> $charsetList) : string
Parameters
- $length : int
-
Result string length.
- $charsetList : array<string|int, mixed>
-
Array of charsets.
Return values
stringgetStringByCharsets()
Returns random (if possible) string for a given charset list.
public
static getStringByCharsets(int $length, string $charsetList) : string
Parameters
- $length : int
-
Result string length.
- $charsetList : string
-
Charset list, must be ASCII.