Code Snippet for random key generation in C#:
private string generateSerialNum()
{
Random r = new Random();
StringBuilder sb = new StringBuilder();
int size = 14;
string legalnums = "0123456789";
for (int i=0; i<9;i++)
{
sb.Append(legalnums.Substring(r.Next(0,legalnums.Length-1)+1,1));
} return sb.ToString();
}
private void SaleOrder_Load(object sender, EventArgs e)
{
txt_SalesID.Text = generateSerialNum();
}
Cheers,
Venkatesan Prabu .J
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Bennet HuberPosted May 2, 2012, 1:35 PM
Two things: a) size is never used, perhaps it belongs where 9 is in the for loop declaration? and b) your serial numbers are guaranteed not to contain 0s