CryptGenRandom function on Windows
CNG-API on Windows
GETRANDOM(2) on LINUX
<?php
string random_bytes ( int $length )
where,
$length = The length of the STRING to be returned in bytes
?>
<?php
// Run this code several times
$len01 = mt_rand(20, 40);
$rndbin01 = random_bytes($len01);
$lenbin01 = strlen($rndbin01);
$rndhex01 = bin2hex($rndbin01);
$lenhex01 = strlen($rndhex01);
echo 'RAW-BIN (' . $lenbin01 . ')<br>' .
$rndbin01 . '<br><br>HEX (' . $lenhex01 . ')<br>' .
$rndhex01;
?>