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
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.