'Code créé par patricktoulon
Private Sub CommandButton1_Click()
Dim tablo, chaine As String, cpt As Long, dico As Object
Dim strLettres, strChiffres, faire, lettre As String, chiffre As String, symb As String, ind As Long
strLettres = Split(StrConv("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", vbUnicode), Chr(0))
strChiffres = Split(StrConv("0123456789", vbUnicode), Chr(0))
Randomize
ReDim tablo(Val(NBMP), 2)
Set dico = CreateObject("Scripting.Dictionary")
Do ' boucle general pour le nombre de mots de passe
cpt = cpt + 1: chaine = "": faire = dico.RemoveAll()
Do 'boucle pour les caracteres
lettre = strLettres(Rnd * UBound(strLettres))
If Not dico.exists(lettre) Then dico(lettre) = "": chaine = chaine & lettre
Loop Until dico.Count = Val(NBCA)
Do 'boucle pour les chiffres
chiffre = strChiffres(Rnd * UBound(strChiffres))
If Not dico.exists(chiffre) Then dico(chiffre) = "": chaine = chaine & chiffre
Loop Until dico.Count = Val(NBCA) + Val(NBCH)
faire = dico.RemoveAll()
Do ' boucle pour mettre en desordre les carateres
ind = Round(Rnd * Len(chaine)): If ind = 0 Then ind = 1
lettre = Mid(chaine, ind, 1)
If Not dico.exists(lettre) Then dico(lettre) = "": tablo(cpt - 1, 0) = tablo(cpt - 1, 0) & lettre
Loop Until dico.Count = Len(chaine)
tablo(cpt - 1, 1) = Len(tablo(cpt - 1, 0)) & " caracteres "
Loop Until cpt = Val(NBMP)
ListBox1.ColumnCount = 2: ListBox1.List = tablo
End Sub