Why is the first random number always the same on some platforms in lua?

前端 未结 5 1067
眼角桃花
眼角桃花 2021-01-18 15:50

Consider the following lua code snippet :

local time = os.time()
for _= 1, 10 do
    time = time + 1
    print(\'Seeding with \' .. time)
    math.randomseed         


        
5条回答
  •  独厮守ぢ
    2021-01-18 16:36

    It's generally a bad idea to call srand multiple times with seeds that are numerically close (and especially bad to do so with time values). In many cases, the variance of the first random number is similar to the variance of the seeds. When dealing with a scripting language that has to convert number representations, it can be even more so.

    Does the same thing occur if you change your seed value by a larger amount?

提交回复
热议问题