當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP mt_getrandmax()用法及代碼示例

PHP mt_getrandmax() 函數是數學函數,用於尋找最大可能的隨機值。

用法:

int mt_getrandmax ( void )

例子1

<?php
echo "By using 'mt_getrandmax()' function your value is:".(mt_getrandmax()); 
?>

輸出:

By using 'mt_getrandmax()' function your value is:2147483647

例子2

<?php
function randomFloat($min = 0, $max = 1) {
    return $min + mt_rand() / mt_getrandmax() * ($max - $min);
}
var_dump(randomFloat());
var_dump(randomFloat(2, 20));
?>

輸出:

float(0.34399861858413) float(13.130184705895)






相關用法


注:本文由純淨天空篩選整理自 PHP mt_getrandmax() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。