简体   繁体   English

在PHP中,无法弄清楚如何在我的最大和最小范围之间生成随机整数

[英]In PHP, can't figure out how to generate random integers between my max and min range

In PHP, I need to find a way to generate random integers between 1 and 46938003261 在PHP中,我需要找到一种方法来生成1到46938003261之间的随机整数

The rand function seems to be unable to generate numbers larger than 9 digits long, which is a problem for me given my 11 digit long max number. rand函数似乎无法生成大于9位数长的数字,考虑到我的11位数长的最大数字,这对我来说是个问题。

rand (1 , 46938003261) rand(1,46938003261)

I realize this is a limitation of PHP on 32 bit systems, and I can verify that I have had the same issue using mt-rand instead of rand. 我意识到这是PHP在32位系统上的局限性,我可以使用mt-rand而不是rand来验证是否存在相同的问题。

How can I generate a random integer between 0 and 46938003261 with PHP? 如何使用PHP生成0到46938003261之间的随机整数?

Thanks! 谢谢!

Append 2 numbers and concatenate them 附加2个数字并将其连接

rand (0 , 46938003261) + rand (10 ,100 ) 

But make sure you convert them to string and then add (?) 但是请确保将它们转换为字符串,然后添加(?)

Another approach is to check the size of string before concatenating them. 另一种方法是在连接字符串之前检查字符串的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM