I've been using this random string generator. But my problem is that this random string generator is repeating itself. I've heard of using the shuffle method but I dont know how to implement it in my code. Any help will be mostly appreciated.
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public static string RandomString2(int length)
{
const string chars = "AB";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
And then in the page load i actually call my 2 methods and combine them in a textbox.
string dummy = RandomString(1);
string dummy2 = RandomString2(1);
txtTagNumber.Text = dummy2.ToString() + dummy.ToString();
Aucun commentaire:
Enregistrer un commentaire