private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
from : https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings
const string src = "abcdefghijklmnopqrstuvwxyz0123456789";
回覆刪除int length = 16;
var sb = new StringBuilder();
Random RNG = new Random();
for (var i = 0; i < length; i++)
{
var c = src[RNG.Next(0, src.Length)];
sb.Append(c);
}
MessageBox.Show(sb.ToString());
More examples on...C# Random string