The Code Developer

Generate Random Alphanumeric String with PHP

This is a simple function that allows you to generate random strings containing Letters and Numbers (alphanumeric) using PHP. The random strings can be used for various purposes, including:

Referral Code
Promotional Code
Coupon Code
OTP Code

This code relies on following PHP functions:
base_convert
sha1
uniqid
mt_rand

function random_code($limit)
{
	return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $limit);
}

echo random_code(8);

//Here's the output samples

mocpkwbn
460djcsn
j1m10z0t
4kj9cy68