$random_hash = md5(uniqid(rand(), true));
That will be 32 alphanumeric characters long and unique. If you want it to be shorter just use substr():
$random_hash = substr(md5(uniqid(rand(), true)), 16, 16); // 16 characters long
Alternative methods to generate random data include:
$random_hash = md5(openssl_random_pseudo_bytes(32));
$random_hash = md5(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
// New in PHP7
$random_hash = bin2hex(random_bytes(32));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…