Random
class Random (View source)
Defines a utility class for creating random data.
Constants
| MAXIMUM_TRIES |
The maximum number of times name() and string() can loop. This prevents infinite loops if the length of the random value is very small. |
Properties
| protected array | $strings | A list of unique strings generated by string(). |
|
| protected array | $names | A list of unique names generated by name(). |
Methods
Generates a random string of ASCII characters of codes 32 to 126.
Generates a random string containing letters and numbers.
Generate a string that looks like a word (letters only, alternating consonants and vowels).
Generates a random PHP object.
Generates sentences Latin words, often used as placeholder text.
Generate paragraphs separated by double new line.
Create a placeholder image.
Details
string
string(int $length = 8, bool $unique = FALSE, callable $validator = NULL)
Generates a random string of ASCII characters of codes 32 to 126.
The generated string includes alpha-numeric characters and common miscellaneous characters. Use this method when testing general input where the content is not restricted.
string
name(int $length = 8, bool $unique = FALSE)
Generates a random string containing letters and numbers.
The string will always start with a letter. The letters may be upper or lower case. This method is better for restricted inputs that do not accept certain characters. For example, when testing input fields that require machine readable values (i.e. without spaces and non-standard characters) this method is best.
string
word(int $length)
Generate a string that looks like a word (letters only, alternating consonants and vowels).
object
object(int $size = 4)
Generates a random PHP object.
string
sentences(int $min_word_count, bool $capitalize = FALSE)
Generates sentences Latin words, often used as placeholder text.
string
paragraphs(int $paragraph_count = 12)
Generate paragraphs separated by double new line.
string
image(string $destination, string $min_resolution, string $max_resolution)
Create a placeholder image.