WireRandom::alphanumeric()
Return random alphanumeric, alpha or numeric string
This method uses cryptographically secure random generation unless you specify true
for
the fast
option, in which case it will use cryptographically secure method only if PHP is
version 7+ or the mcrypt library is available.
Note about the allow
option:
If this option is used, it overrides the alpha
and numeric
options and creates a
string that has only the given characters. If given characters are not ASCII alpha or
numeric, then the fast
option is always used, as the crypto-secure option does not
support non-alphanumeric characters. When the allow
option is used, the strict
option does not apply.
Available since version 3.0.111.
Usage
// basic usage
$string = $wireRandom->alphanumeric();
// usage with all arguments
$string = $wireRandom->alphanumeric(int $length = 0, array $options = []);
Arguments
Name | Type(s) | Description |
---|---|---|
$length (optional) | int | Required length of string, or 0 for random length |
$options (optional) | array | Options to modify default behavior:
|
Return value
string
Exceptions
Method can throw exceptions on error:
WireException
WireRandom methods and properties
API reference based on ProcessWire core version 3.0.251