How can PHP's random functions be enhanced with additional security measures, such as using openssl_random_pseudo_bytes or /dev/urandom?

PHP's random functions, such as rand() or mt_rand(), are not considered secure for cryptographic purposes due to their predictability. To enhance security, it is recommended to use openssl_random_pseudo_bytes() or read from /dev/urandom. This ensures a higher level of randomness and unpredictability in generating secure random numbers.

// Using openssl_random_pseudo_bytes
$randomBytes = openssl_random_pseudo_bytes(32);
$randomNumber = hexdec(bin2hex($randomBytes));

// Reading from /dev/urandom
$randomBytes = file_get_contents('/dev/urandom', false, null, 0, 32);
$randomNumber = hexdec(bin2hex($randomBytes));