这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the help center .
8年前关闭。
我正在尝试使用 lua 生成一个随机数,但它只是吐出最低值。例如,如果我运行:
x = math.random(17,41)
print(x)
它返回:
17
怎么了?
最佳答案
这不一定是真的。所有随机数都不是完全随机的。作为一个例子,你可以看看这个工作代码;这与您发布的问题相同:http://eval.in/17806
如您所见,输出为 38 .
引用 Doub 的回复:
You can use
math.randomseed
to start the pseudo-random sequence elsewhere. You can useos.time
to initialize that with a different value every time you run the program (assuming you allow at lease one second to elapse between runs).
以下是与
randomseed
相同的程序的示例在行动:http://eval.in/17808math.randomseed( os.time() )
x = math.random(17,41)
print(x)
关于random - 在lua中查找随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16258845/