I'm making a webshop for school and had a quick question. I'm trying to write a code that generates a random coupon code and it actually works (did some extreme programming in Console Application), but it's simply not efficient.
static void Main(string[] args)
    {
        Random r = new Random();
        string ALphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        int size = 4;
        char[] code1 = new char[size]
        char[] code2 = new char[size]
        char[] code3 = new char[size]
        for (int i = 0; i < size; i++)
        {
            code1[i] = Alphabet[r.Next(Alphabet.Length)];
            code2[i] = Alphabet[r.Next(Alphabet.Length)];
            code3[i] = Alphabet[r.Next(Alphabet.Length)];
        }
        string code4 = new string(code1);
        string code5 = new string(code2);
        string code6 = new string(code3);
        Console.WriteLine(code4 + " - " + code5 + " - " + code6);
        Console.ReadLine();
    }
This works.. somehow. But I would like to see it more efficient, because when I want to generate 100 coupons... this isn't really the way to do that.
I did see something on joining strings, use string.Insert to get that " - " in between and loop it multiple times, but I couldn't get a clear tutorial on how to do that with... well this kind of code.
Anyone got a efficient and (preferable) easy solution?
=======
UPDATE!
this does end up in a database eventually
 
     
     
    