generating random letters

mmarkym

Member
Joined
Aug 20, 2005
Messages
13
Programming Experience
3-5
Hi, Is there anyway to generate the alphabet randomly with the int(rnd() function or any other way?

mark
 
generate random letter

first make a function to get a random number like

VB.NET:
[/color]Private [/color][/size][size=2][color=#0000ff]Function[/color][/size][size=2] getRandomNumber([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] low [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2], [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] high [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer[/color][/size][size=2]) [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Integer
[/color][/size][size=2]getRandomNumber = [/size][size=2][color=#0000ff]New[/color][/size][size=2] System.Random().Next(low, high)
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Function[color=#000000]

then just pass the random number to the string say on button click ... as it follows:
VB.NET:
[size=2][color=#0000ff]Private [/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myAlphabet [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String[/color][/size][size=2] = "abcdefghijklmnopqrstuvwxyz" [color=teal]'you can add CAPITAL letters too[/color]
 
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] myRandomLetter [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]Char[/color][/size][size=2] = myAlphabet.Substring(getRandomNumber(0, 26), 1)
 
MessageBox.Show(myRandomLetter)
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Sub[color=#000000]
[/color][/color][/size]


Cheers ;)
 

Attachments

  • RandomLetter.zip
    21.2 KB · Views: 35
Last edited:
Back
Top