WireRandom class

Random generators for ProcessWire

Includes methods for random strings, numbers, arrays and passwords.

Usage example

$random = new WireRandom();
$s = $random->alphanumeric(10);
$i = $random->integer(0, 10);

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireRandom class also inherits all the methods and properties of: Wire.

Show class?     Show args?       Only hookable?    

Common

NameReturnSummary 
WireRandom::alpha()
stringReturn string of random ASCII alphabetical letters 
WireRandom::alphanumeric()
stringReturn random alphanumeric, alpha or numeric string 
WireRandom::arrayKey(array $a)
string intGet a random key from given array 
WireRandom::arrayKeys(array $a)
arrayGet a random version of all keys in given array (or a specified quantity of them) 
WireRandom::arrayValue(array $a)
mixed nullGet a random value from given array 
WireRandom::arrayValues(array $a)
arrayReturn a random version of given array or a quantity of random items 
WireRandom::base64()
string arrayGenerate a truly random base64 string of a certain length 
WireRandom::cryptoSecure()
boolIs a crypto secure method of generating numbers available? 
WireRandom::integer()
int arrayGet a random integer 
WireRandom::numeric()
stringReturn string of random numbers/digits 
WireRandom::pass()
stringGenerate and return a random password 
WireRandom::shuffle($value)
string arrayShuffle a string or an array 
WireRandom::string()
stringGenerate a random string using given characters 

Additional methods and properties

In addition to the methods and properties above, WireRandom also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.251