Here is how i used to generate the random key, even though its bit lengthy you can achieve unique random key.
$id.time().uniqid(mt_rand(),true)
uniqid() - this will generate the 13 character uniqid
mt_rand() - generates random number by using Mersenne Twister algorithim and is 4 times more fast then rand()
uniqid(mt_rand()) - prefixing the random generate number with uniqueid
uniqid(mt_rand(), true) - to get more strong random i am enabling entropy of uniqid by setting second parameter to 'true'
$id.time().uniqid(mt_rand(), true) - here $id may be userid, productid or any id which you want to choose, time() will generate current unix time stamp, lastly i will append with my uniqid(...)