Currently my program generates random 8 character strings made from numbers.
See below
public static string GenerateNewCode()
{
string newCode = String.Empty;
int seed = unchecked(DateTime.Now.Ticks.GetHashCode());
Random random = new Random(seed);
// keep going until we find a unique code
do
{
newCode = random.Next(0, 9999).ToString("0000")
+ random.Next(0, 9999).ToString("0000");
}
while (!ConsumerCode.isUnique(newCode));
// return
return newCode;
}
However, I want to be able to create random codes of 8, 9, 10, 11 and 12 numbers.
Not sure the most efficient way of doing this.
My idea was to create a random number between 0 – 9 and then do this X amount of times based on the length of code required.
There must be an easy/more efficient way to doing this …..
or
Easy? yes. Most efficient? maybe not.