# Convert Integer to String • ### Question

• This is probably a very easy task, but I am uncapable of finding the simplest solution to it.

I understand there are many things such as Convert.ToString(6) (this however isn't working). I am trying to find the simplest way to generate random letters, using a random number generator.

 Dim X = Int(Rnd() * 10) + 1 'Generates a random number from 1 - 10MsgBox(Convert.ToString(X))

Then I hoped it would display a "string" character, but it does not.

If anyone has a simple answer, it would be much appreciated.

Brian
Thursday, October 2, 2008 8:24 PM

• Dim someRandom As New Random Dim ai As Integer For x = 0 To 9 ai = someRandom.Next(0, 128) Debug.WriteLine(Convert.ToChar(ai).ToString) Next

• Marked as answer by Wednesday, October 8, 2008 3:09 AM
Thursday, October 2, 2008 8:39 PM
• Random string generator, taking into account capital and lowercase letters
 Dim wordLength As Integer = 8 Dim rand As New Random(DateTime.Now.Millisecond) Dim word As New StringBuilder For i As Integer = 0 To wordLength If (rand.Next(1, 5) Mod 2) = 0 Then word.Append(Chr(rand.Next(65, 90))) Else word.Append(Chr(rand.Next(97, 123))) End If Next Console.WriteLine(word.ToString())

• Marked as answer by Wednesday, October 8, 2008 3:09 AM
Thursday, October 2, 2008 8:46 PM

### All replies

• Dim someRandom As New Random Dim ai As Integer For x = 0 To 9 ai = someRandom.Next(0, 128) Debug.WriteLine(Convert.ToChar(ai).ToString) Next

• Marked as answer by Wednesday, October 8, 2008 3:09 AM
Thursday, October 2, 2008 8:39 PM
• Random string generator, taking into account capital and lowercase letters
 Dim wordLength As Integer = 8 Dim rand As New Random(DateTime.Now.Millisecond) Dim word As New StringBuilder For i As Integer = 0 To wordLength If (rand.Next(1, 5) Mod 2) = 0 Then word.Append(Chr(rand.Next(65, 90))) Else word.Append(Chr(rand.Next(97, 123))) End If Next Console.WriteLine(word.ToString())

• Marked as answer by Wednesday, October 8, 2008 3:09 AM
Thursday, October 2, 2008 8:46 PM
• the seed for random is already clock derived so why

Dim rand As New Random(DateTime.Now.Millisecond)

and didn't you mean not to leave out Z(65, 91)
Thursday, October 2, 2008 9:12 PM
• dbasnett said:

the seed for random is already clock derived so why

Dim rand As New Random(DateTime.Now.Millisecond)

As a demonstration of the options you have with the Random class

dbasnett said:

and didn't you mean not to leave out Z(65, 91)

Typo.

Thursday, October 2, 2008 9:27 PM