Search code examples
c#generatorletters-and-numbers

How to generate a file with all possible 12 character letter/number combinations?


I have been struggling with this for some time, and I can't even figure out where could I start with it. I am trying to create a program that is going to generate a lot of random (I could call them serials). Limit would be from letter A-Z on english uppercase alphabet and numbers from 0-9.

Something like website application at this page http://www.random.org/strings/

but

I would like it to create "all" combinations, none same, of letters and numbers, and save them to text file. I think there are around 200k+ combinations.

They would be 12 characters. Example:

  • T9T1P63WBYYZ
  • SCI1V7SAV9F5
  • 5OLN7UQS7MIE

I would like to create it in C# if it is possible, but I have no idea where should I even start. I'm browsing google and similar projects for around a week, and I need it as university project. If someone would help I would be very happy.


Solution

  • Hehe.. if you have the time!

    Asked yesterday, seen a great solution by L.B here:

    How to get all the possible 3 letter permutations?

    His simple solution, just change the alphabet:

    var alphabet = "abcdefghijklmnopqrstuvwxyz1234567890";
    
    var query = from a in alphabet
                from b in alphabet
                from c in alphabet
                from d in alphabet
                from e in alphabet
                from f in alphabet
                from g in alphabet
                from h in alphabet
                from i in alphabet
                from j in alphabet
                from k in alphabet
                from l in alphabet
    
                select "" + a + b + c + d + e + f + g + h + i + j + k + l;
    
    foreach (var item in query)
    {
        Console.WriteLine(item);
    }
    

    A more advanced answer might be the CartesianProduct