hello everyone, I'm trying to generate numbers that are not repeated within 4 maps, but the algorithm is not so efficient, despite "it makes sense in my logic", can someone verify if there is no inconsistency with the "continue" inside the Do while ?
algorithm >
Can anyone see the problem that I'm not seeing?
algorithm >
B4X:
Sub Process_Globals
Private Bot1_Cards As Map
End Sub
Sub AppStart (Args() As String)
Bot1_Cards.Initialize
For i = 0 To 15
Bot1_Cards.Put(i,GenerateDeckCardsUnique)
Next
Log("------------------------------------")
For i = 0 To Bot1_Cards.Size-1
Log("1x"&i&"-"&Bot1_Cards.Get(i))
Next
end sub
Sub GenerateDeckCardsUnique As Int
Dim isLoop As Int = 1
Dim GeneratedCard As Int
Do While ( isLoop = 1)
GeneratedCard = Rnd(0,51)
Log("GENERATED NUMBER = "&GeneratedCard)
If (Bot1_Cards.Size>0) Then
For j = 0 To Bot1_Cards.Size-1
Log("Card1="&Bot1_Cards.Get(j))
If (GeneratedCard = Bot1_Cards.Get(j)) Then
Log("BOT1 - CARD EXISTS")
Continue '
End If
Next
Else
Log("EMPTY FOR WHILE")
End If
isLoop = 0
Return GeneratedCard
Loop
End Sub
Can anyone see the problem that I'm not seeing?