Hi guys,
I am doing this project where I needs to generate up to 10 million serial numbers. Does any one now how can I do it?

Because of the huge number of serials number that I need to verify. I need a algorithem instead of just storing all the serial in the database and access it.

For example to check whether

abcdef is the correct serial, it should go through an algorithem and pass the algorithem to verify that the serial number is correct.

Does any one have experience on this? Its urgent.

    If it doesn't really matter how it comes out, you could use md5("string"); to generate encrypted 'serials' (although it's a 32-character hex code, not a number).

    Then just say if md5({$input} == databasedserial
    {
    echo ("serial is correct");
    ...

      yea i would use md5 something like that with a random number fuction and then use a for and repeat it 10000 times something like this

      <?
      $serials = "10000";
      for ($i = "0"; $i< $serials; $i++){
      $text = md5(rand(0,65432));
      echo "$text <br>";
      }
      
      ?>
      

      it works _ you could put it into a mysql db or something buy doing this:

      <?
      mysql_connect('host','user', 'pass');
      mysql_select_db('db');
      $serials = "10000";
      for ($i = "0"; $i< $serials; $i++){
      $text = md5(rand(0,65432));
      $query = "INSERT INTO serials(number) VALUES('$text')";
      mysql_query($query);
      }
      
      ?>
      

        Sounds like you're looking for some sort of error-detection code. Lessee 10 million numbers - that's seven independent digits 0000000-9999999. Can't get past needing that much independent information (otherwise you can't have 10 million distinct serial numbers). Five alphabetic characters [a-z] will give you 11881376 IDs, but one of those IDs will be "idiot". So let's stick to digits.

        With those seven digits out of the way. the next thing you need are more digits tacked on that will help detect if any errors were made. A Google search on "error dectection" algorithms should turn something up (add -CRC to get past all the CRC citations, if there are too many). You're bound to find something applicable. You could also adapt something like the Luhn algorithm used in credit card validation (an example implementation in PHP being here).

        I'm looking a check-digit scheme (there's another phrase to search on) right now, based on a dihedral group (D5, as it happens) developed in the late '60s, but it's described in group-theoretic terms, and it would take me a bit longer than "urgently" demands to convert it into an algorithm and implement it in PHP. It identifies all single-digit typos, any single transposition of two digits, and about 90% of other types of errors.

        So yeah, a search on "error detect*" codes, or checksum algorithms etc. etc. will be bound to turn something up. You may have to convert it into PHP yourself, but it's likely to involve nothing more than a bit of arithmetic.

          8 days later

          most of the algorithm I found involve only converting a number into a so called encoded or encrypted number. Are there anyways I can convert a number into a mixture of alphabet and numerics? I do understand that we can use methods like using chr to get the alphabet to be placed in the serial etc, but I do hope there r something better than just plain subsitution.,.

          Hope someone can help =0

            whats the problem with using the md5 as the serial?

              md5 is one way if I am not wrong? Because I need to verify the serial after that, I can't have a one way algorithm, unless you can correct me by updating the unknowledgable me that md5 is two way.

                Conversion into alphanumeric is simple enough; base_convert() the number into base 36, for example, will write the serial numbers using the digits 0123456789abcdefghijklmnopqrstuvwxyz. But that won't give you any sort of validation.

                Do you need any sort of encryption? It sounds like a plain checksum would do.

                The idea of making a checksum class amused me, and since I had that description of one method sitting in front of me, I decided to write a class that would do the job.

                And because I'm a fantastically nice guy, I've attached it here.

                Note that it works with strings of decimal digits. In other words, your ten million serial numbers will be 0000000 to 9999999 - and with this code, they'd be followed by a one-digit checksum. Other sets of characters can be used, e.g., with the base_convert() method above, you'd base_convert the serials into base 10 before using these functions on them, and you'd use base_convert() to get computed serial numbers back into base 36.

                  Thank you for all the contributions, they taught me alot. But perhaps I should be more clear about my situation.

                  I would like to generate serials like 32jhdau3 (alpha numeric)
                  perhaps 30 thousand to a million of them.

                  The problem is I do not want to enter the serials into a database, then when a user use it to register my software or whatever I am using the serial for, I have to open database, extract data etc. It makes the process slow if it has a million data.

                  I would prefer a 2 way algorithm something like the mod10 algorithm but harder to derive, before I wouldn't want any users to run the mod and generate another million identical numbers.

                  Scenario
                  Generating : Algorithem -> dksad820i
                  Validating : dksad82oi -> Algorithem -> Derive to a number.

                  To generate the numbers i can simply do a while loop from 000000000 -> 999999999 to go through the algorithem, if it derives to the number den it will be recorded down. Once its recorded down it would go through another algorithem to become alpha numeric (which should also be a 2 way algorithem).

                  Any help?
                  A little too much to ask for I guess...

                    Originally posted by Daveyz83

                    Any help?

                    What, you mean all that I wrote just a few minutes ago doesn't do what you describe? Lessee - its reversable, it's "something like" the mod10 algorithm, it's harder to derive ...

                    As for "simply doing a while loop" that goes through a billion records, that would be massively slower than a database lookup.

                      Write a Reply...