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

前端 未结 5 1034
眼角桃花
眼角桃花 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:25

    If you use the same seed, you will get the same string of numbers from the C rand() function, but you should get a different string of numbers each time since you appear to be using the current time as the seed.

    Edit: I suppose I should elaborate on my answer. If you are not getting a random string of numbers when seeding with os.time(), you may not be getting what you expect from that function call. What are the values you are getting back from os.time()?

    Edit #2: Also, what is the output from that block of code?

提交回复
热议问题