Hey guys, I've been having a bit of a problem using the while function.

Here is my code (Simplified):

Dim RandomNumber3 As Random
Dim RandomOutput3 As Integer
RandomNumber3 = New Random()
RandomOutput3 = RandomNumber3.Next(1, 9)

Dim RandomClass As Random
RandomClass = New Random()
       

While (RandomOutput3 = RandomOutput Or RandomOutput2)
            RandomOutput3 = RandomClass.Next(1, 9)
End While

When running the debug, the program crashes, and when I step into the program, I find that this While statement becomes an infinite loop. This is a program that uses random number generators to assign a value to something, and this while statement is necessary so that there is never two of the same values showing (RandomOutput, RandomOutput2 & RandomOutput) Have to be different to one another.

If you need any more details, If requested I can attach my program.

Thanks, Toby.

Recommended Answers

All 2 Replies

How about?:

While (RandomOutput3.Equals(RandomOutput) Or RamdomOutput3.Equals(RandomOutput2))

Wonderful! It works - Haha As I said - Hadn't used While's before. Thanks a lot ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.