1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Function Devinette()
Const clNbEssais As Long = 5000, clNbChoix As Long = 3 'Doit être >= 3 choix
Dim lInitChoix As Long, lVide As Long, lSecondChoix As Long, lNbInitChoix As Long
Dim lNbSecondChoix As Long, lNbMauvaisChoix As Long, i As Long, lSolution As Long
Dim sMsg As String
Randomize
For i = 1 To clNbEssais
lSolution = Int(Rnd() * clNbChoix) + 1
lInitChoix = Int(Rnd() * clNbChoix) + 1
Do
lVide = Int(Rnd() * clNbChoix) + 1
Loop While lVide = lInitChoix Or lVide = lSolution
Do
lSecondChoix = Int(Rnd() * clNbChoix) + 1
Loop While lSecondChoix = lInitChoix Or lSecondChoix = lVide
Select Case lSolution
Case lInitChoix
lNbInitChoix = lNbInitChoix + 1
Case lSecondChoix
lNbSecondChoix = lNbSecondChoix + 1
Case Else
lNbMauvaisChoix = lNbMauvaisChoix + 1
End Select
Next i
sMsg = "Nombre d'essais : " & clNbEssais & vbTab & "Nombre de choix possibles : " & clNbChoix & vbCrLf & _
"=> Choix initial correct : " & lNbInitChoix & Format(lNbInitChoix / clNbEssais, " (0.00%)") & vbCrLf & _
"=> Choix secondaire correct : " & lNbSecondChoix & Format(lNbSecondChoix / clNbEssais, " (0.00%)") & vbCrLf & _
"=> Choix incorrect : " & lNbMauvaisChoix & Format(lNbMauvaisChoix / clNbEssais, " (0.00%)")
MsgBox sMsg, vbInformation, "Théorème de Bayes"
End Function |
Partager