PHP随机浮点数random float

function random_float() {
    return (float)mt_rand() / (float)mt_getrandmax();
}
function random_float() {
    return (float)rand() / (float)getrandmax();
}
function random_float($min = 0, $max = 1) {
    return random_int($min, $max - 1) + (random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX );
}
function random_float($min = 0, $max = 1) {
    return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}

Leave a comment

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