I want to generate a different random string every time I use the function.
public static Dictionary<string, long> Giftcodes = new Dictionary<string, long>();
private static Random random = new Random();
public static string GenerateCode()
{
string code = "";
string chars = "abcefhijkmnorsuvwxyzABCDEFHIKMNORSUVWXYZ1234567890";
if (Giftcodes.Keys == null)
{
code = new string(Enumerable.Repeat(chars, 16)
.Select(s => s[random.Next(s.Length)]).ToArray());
}else
{
while (!Giftcodes.Keys.Contains(code))
{
code = new string(Enumerable.Repeat(chars, 16)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
}
return code;
}
I did a little bit of researches but I found nothing.