gmp_random_bits()函數是PHP中的一個內置函數,它會生成一個隨機數。因此,隨機數將在0到(2 *位)– 1的範圍內。這裏的位必須大於0,並且位的最大值受可用內存的限製。這裏的GMP是指(GNU多精度),用於大數。
用法:
GMP gmp_random_bits ( int $bits )
參數:上麵的函數接受如上所述和以下描述的單個參數:
- $bits : IT僅接受一個參數。此參數可以是PHP 5.5及更低版本中的GMP數字資源,PHP 5.6及更高版本中的GMP對象,或者也可以傳遞數字字符串,前提是可以將該字符串轉換為數字。
返回值:該函數返回一個隨機的GMP編號。
例子:
Input : bits = 3 Output : 3 Input : bits = 5 Output : 15 Note: Output will vary every time on execution
示例1:
<?php
// PHP program to demonstrate
// the gmp_random_bits() function
// random number within 0 to 15
$rand = gmp_random_bits(4);
echo gmp_strval($rand) . "\n";
?>
輸出:
10
示例2:
<?php
// PHP program to demonstrate
// the gmp_random_bits() function
// random number within 0 to 31
$rand = gmp_random_bits(5);
// gmp_strval converts GMP number to string
// representation in given base(default 10).
echo gmp_strval($rand) . "\n";
?>
輸出:
15
參考:http://php.net/manual/en/function.gmp-random-bits.php
相關用法
- p5.js day()用法及代碼示例
- PHP dir()用法及代碼示例
- PHP each()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js second()用法及代碼示例
- p5.js int()用法及代碼示例
- d3.js d3.max()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- p5.js str()用法及代碼示例
- p5.js arc()用法及代碼示例
- d3.js d3.hcl()用法及代碼示例
- d3.js d3.lab()用法及代碼示例
注:本文由純淨天空篩選整理自priya_1998大神的英文原創作品 PHP | gmp_random_bits() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。