Thursday, February 26, 2009

Generating random number asp.net c#

using System.Security;

protected void Page_Load(object sender, EventArgs e)
{ string abc = "";
for (int i = 0; i < abc =" RandomNumberGenerator(6);" rng =" System.Security.Cryptography.RandomNumberGenerator.Create();" chars =" new" validchars = "abcdefghijklmnopqrstuvwxyzABCEDFGH IJKLMNOPQRSTUVWXYZ1234567890!@$%^*();
for (int i = 0; i < length; i++)
{ byte[] bytes = new byte[1];
rng.GetBytes(bytes);
Random rnd = new Random(bytes[0]);
chars[i] = validChars[rnd.Next(0, 61)];
}
return (new string(chars));
}
}

No comments:

Post a Comment