Random 在Lua中设置随机种子

Random 在Lua中设置随机种子,random,lua,Random,Lua,我想知道如何在Lua中使用math.randomseed。事实上,当用作函数时,我会得到一个错误,而当用作变量时,它就不起作用了 > math.randomseed = 0 > math.random() 0.51340090995654 > math.randomseed = 0 > math.random() 0.9522297247313 > math.randomseed (44) stdin:1: attempt to call a number valu

我想知道如何在Lua中使用
math.randomseed
。事实上,当用作函数时,我会得到一个错误,而当用作变量时,它就不起作用了

> math.randomseed = 0
> math.random()
0.51340090995654
> math.randomseed = 0
> math.random()
0.9522297247313
> math.randomseed (44)
stdin:1: attempt to call a number value (field 'randomseed')
stack traceback:
    stdin:1: in main chunk
    [C]: in ?
math.randomseed()
是存储在
math
表中
randomseed
名称下的函数

在您为
randomseed
name下的
math
表分配了一些值之后,您丢失了存储在那里的原始值—实际设置种子的函数。你不能执行这个数字,因为它不是一个函数

首先将调用
math.randomseed()
作为函数,不要在那里分配数字