gmp_random_bits()函数是PHP中的一个内置函数,它生成一个随机数。因此,随机数将介于0和(2*位)–1之间。这里的位必须大于0,位的最大值受可用内存的限制。这里指的是GMP (GNU多精度) 这是针对大数字的。
null
语法:
GMP gmp_random_bits ( int $bits )
参数: 上述函数接受一个参数,如上所述,如下所述:
- 美元比特: 它只接受一个参数该参数可以是PHP5.5及更早版本中的GMP数字资源,PHP5.6及更高版本中的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 ) . "" ; ?> |
输出:
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 ) . "" ; ?> |
输出:
15
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END