//Using For loop
public void
Generate_Random_String()
{
char[] charSet =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
string Random_String = "";
Random RandomNo = new
Random();
byte[] RandomBytes = new
byte[32];
RandomNo.NextBytes(RandomBytes);
for (int i = 0; i
< 32; i++)
Random_String = Random_String + Convert.ToString(charSet[RandomBytes[i]
% 62]);
}
//Othere
public void
Generate_RandomString()
{
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var random = new Random();
var result = new string(Enumerable.Repeat(chars,
30) .Select(s => s[random.Next(s.Length)]).ToArray())+DateTime.Now.ToString("yyyyMMddhhmmss");
}
//Result=jdu3tbdi8596mMHFROP20150412042010
No comments:
Post a Comment