New Random Number Not Generating

前端 未结 1 1870
误落风尘
误落风尘 2021-01-26 08:18

Hi when I run this piece of code and I return a false distance, a new random number is not generated. The same random number is continually generated, thus putting me into an in

相关标签:
1条回答
  • 2021-01-26 08:57

    You're creating back-to-back new instances of Random in your loop. Just create one (outside the loop!), and ask it for random numbers when you need new values. Think of it as being like digging a well - you don't dig a new well each time you want a drink of water, you dig one well and go back to it for as many drinks as you need.

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