Fill Random?
Hi. I want to fill textBox1, textBox2 and textBox3 when I click button1 .. (with random letters and specified length like 5-letter word) what code should I write in button1 click event? I can't find good information about that.. but I think I have to use string. right?
Csharp NinjaPosted Feb 1, 2012, 7:14 PM
Sarah ReynoldsPosted Jan 27, 2012, 9:01 PM
{
//Initiate objects & vars
Random random = new Random();
String randomString = "";
int randText;
//Loop 'length' times to generate a random number or character
for (int i = 0; i < length; i++)
{
random.Next(1, 3);
randText = random.Next(97, 123); //char {a-z}
//append random char to random string
randomString = randomString + (char)randText;
}
//return the random string
return randomString;
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = generateRandomString(5); //or however long you want the string
}
Hope it helps,
Sarah.