Lua math.random not working

前端 未结 1 1072
野性不改
野性不改 2020-11-29 11:22

So I\'m trying to create a little something and I have looked all over the place looking for ways of generating a random number. However no matter where I test my code, it r

相关标签:
1条回答
  • 2020-11-29 12:02

    You need to run math.randomseed() once before using math.random(), like this:

    math.randomseed(os.time())
    

    One possible problem is that the first number may not be so "randomized" in some platforms. So a better solution is to pop some random number before using them for real:

    math.randomseed(os.time())
    math.random(); math.random(); math.random()
    

    Reference: Lua Math Library

    0 讨论(0)
提交回复
热议问题