0

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.

Mark Cidade
  • 98,437
  • 31
  • 224
  • 236
Sandra
  • 41
  • 3
  • 6
  • 2
    12 characters string would give you 36^12 possible combination, not 2^6. Which (given that we have 2 bytes per character) will result in a file of around 105 billion terabytes – Evgeny Lukashevich Dec 16 '12 at 16:24
  • 1
    Do you need it for a one time generation? Meaning you don't have to try and reproduce the number at a later time? Also - does it have to go through a validation to ensure the "serial" is valid? Have you looked at the GUID classes? – tsells Dec 16 '12 at 16:25
  • 4
    ... and assuming you can generate *`1` million* elements per second, will take *`150` thousands* years. – k.m Dec 16 '12 at 16:33
  • 7
    Think about just the numbers, not the letters. All possible combinations of numbers less than a certain length is easy to compute: the number of twelve-character strings made out of numbers is 1000000000000 -- twelve zeros. By what logic are you computing that there are 200000 such strings? – Eric Lippert Dec 16 '12 at 16:37

1 Answers1

4

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

Community
  • 1
  • 1
Moka
  • 262
  • 1
  • 9