بالاضافة لحل الاخ ممدوح
باستخدام Ling
كود :
Private randoms As New Random()
Private Function RandomPassword(len As Integer) As String
Const CharSamples As String = "abcdefghijklmnopqrstuvwxyz"
Return New String(Enumerable.Repeat(CharSamples, len).[Select](Function(x) x(randoms.[Next](x.Length))).ToArray())
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i = 0 To 9
ListBox1.Items.Add(RandomPassword(6))
Next
End Sub
كما و يمكنك استخدام كلاس منفصل لقيام بالعملية
بنية الكلاس
كود :
Imports System.Security.Cryptography
Imports System.Text
Public Class PassGen
Public Function GetUniqueKey(MSize As Integer) As String
Dim CharSamples As Char() = New Char(61) {}
CharSamples = "abcdefghijklmnopqrstuvwxyz".ToCharArray()
Dim Byetdata As Byte() = New Byte(0) {}
Using crypto As New RNGCryptoServiceProvider()
crypto.GetNonZeroBytes(Byetdata)
Byetdata = New Byte(MSize - 1) {}
crypto.GetNonZeroBytes(Byetdata)
End Using
Dim result As New StringBuilder(MSize)
For Each b As Byte In Byetdata
result.Append(CharSamples(b Mod (CharSamples.Length)))
Next
Return result.ToString()
End Function
End Class
الاستدعاء
كود :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim keyss As New PassGen
For i = 0 To 9
ListBox1.Items.Add(keyss.GetUniqueKey(6))
Next
End Sub