Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi guys, I need help with my queue number generator.

Basically, i need to generate a 5 character string with the letter 'A' at the front followed by 4 random numbers

example:

A6932
A1038
A0193

C#
Random random = new Random();
int length = 5;

for (int i = 0; i < length; i++)
{
	//if random.Next() == 0 then we generate a random character
	if (random.Next(0, 3) == 0)
	{
		tb_queuenum.Text += ((char)random.Next(65, 91)).ToString();
	}
	else //if random.Next() == 0 then we generate a random digit
	{
		tb_queuenum.Text += random.Next(0, 9);
	}
}


These are my codes right now, any help will be deeply appreciated <3
If there's a better alternative to my codes please share.
God bless.
Posted
Updated 6-Jul-15 10:59am
v2
Comments
[no name] 6-Jul-15 16:58pm    
Help... with what? You did not describe any kind of problem....

1 solution

Not sure what exactly your issue is, but you did ask if there was a better way to achieve this.

C#
int min = 0;
int max = 9999;

Random random = new Random();
int randomInt = random.Next(min, max);

var randomValue = String.Format("A{0:D4}", randomInt);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900