I need to make a program that generates 5 random numbers and letters, in VB9 but I am having trouble. Can someone help me ? =]
iBotModz CBox
[VB]How do I generate random numbers and letters?
Started by littlechikon, Jul 09 2009 02:53 PM
3 replies to this topic
#1
Posted 09 July 2009 - 02:53 PM
#2
Posted 09 July 2009 - 02:58 PM
Module ye Sub Main() Dim intRandomNumber As Integer = GenerateRandomInteger(1000, 9999) Dim strRandomString As String = GenerateRandomString(16) Console.WriteLine("Random Number:" & intRandomNumber.ToString()) Console.WriteLine("Random String:" & strRandomString) Console.ReadLine() End Sub Private Function GenerateRandomInteger(ByVal intMin As Integer, ByVal intMax As Integer) As Integer Dim randomNumber As Random = New Random Return randomNumber.Next(intMin, intMax) End Function Private Function GenerateRandomString(ByVal intLenghtOfString As Integer) As String Dim randomString As StringBuilder = New StringBuilder Dim randomNumber As Random = New Random Dim appendedChar As Char For i As Integer = 0 To intLenghtOfString appendedChar = Convert.ToChar(Convert.ToInt32(26 * randomNumber.NextDouble()) + 65) randomString.Append(appendedChar) Next Return randomString.ToString() End Function End Module
#3
Posted 09 July 2009 - 03:04 PM
=O thanks
#4
Posted 10 July 2009 - 12:42 PM
Or..
Life is simple
Dim Random As New Random() TextBox1.Text = Chr(Random.Next(65, 90)) & Chr(Random.Next(65, 90)) & Chr(Random.Next(65, 90)) & Chr(Random.Next(65, 90))
Life is simple