dimanche 15 février 2015

Visual Basic - Random Number based on existing list of Numbers

Currently I have the code below. it reads the file db.lcz line by line and puts each result into the array as an item.


In the db.lcz I have a 10 digit number on each line and I want to get a new random number based on the existing numbers from said file.


--


Any ideas are welcome, I have tried a few options but such as a for loop etc but I keep getting lost. I know I have to check each characters value against one another for the probability aspect but Im not sure how to continue. All help is appreciated.


Thanks!



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim lines() As String = IO.File.ReadAllLines("db.lcz")
Dim codeArray As New ArrayList()

For x As Integer = 0 To lines.GetUpperBound(0)
codeArray.Add(lines(x))
Next
For x = 0 To codeArray.Count - 1
MsgBox(codeArray.Item(x))
Next




Dim rng As New Random
Dim number As Integer = rng.Next(1, 1000000000) 'Test.GenerateDigits(rng, 9)
Dim digits As String = number.ToString("0000000000")
MsgBox(digits)
End Sub

Private Shared Function GenerateDigits(ByVal rng As Random, _
ByVal length As Integer) As String
Dim chArray As Char() = New Char(length - 1) {}
Dim i As Integer
For i = 0 To length - 1
chArray(i) = Convert.ToChar(rng.Next(10) + &H30)
Next i
Return New String(chArray)
End Function




Aucun commentaire:

Enregistrer un commentaire