Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/244.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 生成非固定长度大随机数(bigint)_Php_Mysql - Fatal编程技术网

Php 生成非固定长度大随机数(bigint)

Php 生成非固定长度大随机数(bigint),php,mysql,Php,Mysql,如何生成非固定长度的大随机数?e、 g.在MySQL的bigint范围内。mt_rand函数不支持如此大的数字。使用多个随机函数: const max_limit=10000; a=mt_rand()*max_limit*max_limit + mt_rand()*max_limit + mt_rand(); MySQL的BIGINT是8字节大。让我们计算一个未签名的BIGINT echo unpack('H*', mcrypt_create_iv(8))[1]; 或者对于

如何生成非固定长度的大随机数?e、 g.在MySQL的bigint范围内。mt_rand函数不支持如此大的数字。

使用多个随机函数:

const max_limit=10000;
a=mt_rand()*max_limit*max_limit + mt_rand()*max_limit + mt_rand();

MySQL的BIGINT是8字节大。让我们计算一个未签名的BIGINT

echo unpack('H*', mcrypt_create_iv(8))[1];
或者对于<5.4且不支持函数数组解引用的php版本

echo current(unpack('H*', mcrypt_create_iv(8)));
见:

您运行的是32位PHP还是64位PHP?那么它是什么,非固定/无限还是受mysql bigint范围限制-可能受到mysql bigint范围的限制,可能在10亿到1万亿之间,等等。