Dim i As Integer, n As Integer Dim tableau(1 to 6) As Integer Randomize For i = 1 To 6 Do n = Int(6 * Rnd + 1) Loop Until tableau(n) = 0 tableau(n) = n Print n Next i
For j = 1 To i Step 1 If n <> tableau(j) Then tableau(i) = n Else GoTo debut End If Next j
Dim trouvé As Boolean = False For j = 1 To i Step 1 If n = tableau(j) Then trouvé = True End If Next j If Not trouvé Then tableau(i) = n Else GoTo debut Endif
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim i As Integer, j As Integer, n As Integer Dim tableau(1 to 6) As Integer Randomize WHILE i < 6 n = Int(((6 - 1) * Rnd) + 1) Dim trouvé As Boolean = False For j = 1 To i Step 1 If n = tableau(j) Then trouvé = True End If Next j If Not trouvé then tableau(i) = n Form1.Print tableau(i) i = i + 1 End if WEND
"Until tableau(n) = 0" pourquoi utilises tu la variable n comme indice du tableau?Tout simplement afin de ne pas avoir un chiffre déjà tiré au hazard.
Dim i As Integer, n As Integer Dim tableau(1 To 6) As Boolean Randomize For i = 1 To 6 Do n = Int(6 * Rnd + 1) Loop Until tableau(n) = False tableau(n) = True Print n Next i