You could simply add another random function, we'll use rand(0,1)
this will generate 0 or 1, if it's 1 $status = 1
if it's 0 $status = -1
. When we return the value we do multiplication by $status:
function strongRand($bytes, $min, $max)
{
$status = mt_rand(0,1) === 1 ? 1:-1;
if(function_exists('openssl_random_pseudo_bytes'))
{
$strong = true;
$n = 0;
do{
$n = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes, $strong)));
}
while($n < $min || $n > $max);
return $n * $status;
}
else{
return mt_rand($min, $max) * $status;
}
}