Laravel String Helper Function: quick_random

November 16, 2016 —John Koster

The quickRandom helper method is similar to random in that it generates a random string to a given $length. The quickRandom helper method does not rely on the OpenSSL extension, and generates its random strings from a pool of alpha-numeric characters.

The signature for the quickRandom helper method is:

quickRandom($length = 16)

While the quickRandom function is useful for fast generation of random strings (for use in URI's, tokens, etc), , it should not be used in instances where cryptographically secure strings are required.

The following examples show quickRandom sample output:

1use Illuminate\Support\Str;
2 
3// LDM03NP6upx1NUMt
4echo Str::quickRandom();
5 
6// jlxyb2YBCxPLZ6OL
7echo Str::quickRandom();
8 
9// rlLdOd0YIWZxdmTZMBkItbsduCNUKck2
10echo Str::quickRandom(32);

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.