您还可以考虑使用OpenSSL openssl_random_pseudo_bytes,该版本自PHP 5.3起可用。
string openssl_random_pseudo_bytes ( int $length [, bool &$crypto_strong ] )
生成一串伪随机字节,其字节数由length参数确定。它还指示是否使用了加密功能强的算法来生成伪随机字节,并通过可选的crypto_strong参数来执行此操作。很少会出现FALSE,但是某些系统可能已损坏或过旧。
从PHP 7开始,还有
random_bytes可用的功能
string random_bytes ( int $length )



