Public tablo(1000), Flag As Boolean
Function LoiBenford(x)
If Flag = False Then ListeBenford ' Construction table
LoiBenford = tablo(1 + Int(999 * Rnd)) ' Renvoi valeur
End Function
Sub ListeBenford()
' Nb % Qté pour 1000
'1 30,1% 301
'2 17,6% 176
'3 12,5% 125
'4 9,7% 97
'5 7,9% 79
'6 6,7% 67
'7 5,8% 58
'8 5,1% 51
'9 4,6% 46
Dim N As Integer, Limite()
Limite = Array(1, 301, 477, 602, 699, 778, 845, 903, 954, 1000)
N = 0
For i = 1 To 1000
tablo(i) = N
N = N + 1
If N = 10 Then N = 0
Next i
For i = 0 To 8
For j = Limite(i) To Limite(i + 1)
tablo(j) = (10 * (i + 1)) + tablo(j)
Next j
Next i
Flag = True
End Sub