Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在 Lua 中获得一个随机的 16 位数字。我写的东西在逻辑上不适合我。math.random 如何处理指数?
这就是我不断得到的。
> return math.random(10^15, 10^16) > -1637272360
如果您想要一个 16 位数字,请尝试以这种方式生成它们:
local num = math.random( 10^7, 10^8 ) num = tostring(num)..math.random( 10^7, 10^8 )
然后将变量保留为num字符串类型。作为一个数字,它将值转换为指数形式(因为非常大;在您的情况下> 10^14;指数值)或其他方式,您可以将它们存储为(n)十六进制字符串?
num
> 10^14