Do the Randomize outside the loop.

This will then prevent the (pretty high, depending on your processor speed) chance that the random numbers generated by Rnd() will be started from the same seed.

I would also suggest that you switch to a class level .NET Random Class[^] which would make your Rand_between routine un-necessary.

But nothing will guarantee that no two numbers in a sequence of random numbers is the same: that is the whole idea of random numbers - that the next number does not depend on the previous values. You are as likely to get a random number "x" followed by the same random number "x" as you are to get "x" followed by "x + 1": 1 in (number of values in the entire range). So if you generate numbers between 0 and 9 inclusive, the probability of getting any specific number are 1:10 each and every time.

If you need to ensure that you do not generate the same random number twice in any number space, then you will have to do a lot more work - and probably badly damage the randomness of the numbers you do get.

16,020,261 members