I'm making Bulls And Cows game and I want to randomly generate a number with four different digits.
Randomize()
Do
Random = Int(9000 * Rnd()) + 1000
'If (hasDupes = True)
randomTwo = Random
For i = 0 To randomTwo.Length - 1
For j = 0 To randomTwo.Length - 1
If randomTwo(i) = randomTwo(j) Then
dupes = False
Exit For
End If
Next
Next
Loop Until dupes = True
^ That's what I have so far but it ain't working. Is there any function how I can find if there are duplicate characters or where is my mistake ?
Here my implementation
EDIT: Additional check first number must be > 0 after reading RLH comment
This will return four unique numbers.