gmp_random_seed()是PHP中的一个内置函数,用于设置RNG种子( 随机数生成 ).
null
语法:
void gmp_random_seed ( mixed $seed )
参数: gmp_random_seed()函数接受一个参数,如下所述:
- $seed: 它是gmp_random_seed()函数所需的唯一参数,该函数将为 gmp_random() , gmp_随机_范围() 和 gmp_随机_位() 功能。该参数可以是PHP5.5或更早版本中的GMP资源,PHP5.6及更高版本中的GMP对象,也可以是允许传递数字字符串的参数,前提是可以将该字符串转换为数字。
返回值: gmp_random_seed()函数成功时返回NULL,失败时返回FALSE。
注:
Warning: The function generates an E-Warning and returns False if the seed is not valid.
例如: 下面的程序演示了PHP中的gmp_random_seed()函数:
项目1:
<?php // PHP code implementing the gmp_random_seed function // setting the seed gmp_random_seed(100); var_dump(gmp_strval(gmp_random(1))); ?> |
输出:
string(19) "7842303329126688544"
项目2:
<?php //php code implementing the gmp_random_seed() function // set the seed to something else gmp_random_seed(gmp_init(-100)); var_dump(gmp_strval(gmp_random_bits(10))); ?> |
输出:
string(3) "800"
方案3:
<?php //PHP code implementing gmp_random_seed() function // set the seed to something invalid var_dump(gmp_random_seed( 'not a number' )); ?> |
输出:
gmp_random_seed(): Unable to convert variable to GMP - string is not an integer -- at line 5 bool(false)
相关文章:
参考: http://php.net/manual/en/function.gmp-random-seed.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END