mt_rand & mt_getrandmax functions

<?php

function generateRandomFloat(float $minValue, float $maxValue): float
{
    return $minValue + mt_rand() / mt_getrandmax() * ($maxValue - $minValue);
}

$minValue = 10.5;
$maxValue = 20.5;
$randValue = generateRandomFloat($minValue, $maxValue);

echo $randValue;

Leave a Comment

Your email address will not be published. Required fields are marked *