类型 函数 库 math.* 返回值 无 修订版 发行版 2024.3703 关键词 randomseed 请参阅 math.random()
为伪随机数生成器设置“种子”。同一个种子每次都会生成同一序列的随机数,这在测试时很有用,但通常更希望对每次运行采用不同的序列,例如将当前时间用作种子(见下文)。
math.randomseed( seed )
数字. 一个数字。
-- Produces a different sequence each time (assuming enough time between invocations) math.randomseed( os.time() )
-- Produces the same sequence of numbers math.randomseed( 1234 ) print ( math.random(), math.random(), math.random() ) --> 0.31763056866714 0.416967588671 0.97426279353642 math.randomseed( 1234 ) print ( math.random(), math.random(), math.random() ) --> 0.31763056866714 0.416967588671 0.97426279353642