Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:30:09+00:00 2026-06-10T03:30:09+00:00

Does anybody know any algorithm which generates unique 8 or 9 digits number for

  • 0

Does anybody know any algorithm which generates unique 8 or 9 digits number for a given string? It would be better to have a php example also if not then at least the algorithm.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:30:11+00:00Added an answer on June 10, 2026 at 3:30 am

    You could use crc32() and return the len.

    <?php 
    function crc_string($str, $len){
        return substr(sprintf("%u", crc32($str)),0,$len);
    }
    echo crc_string('some_string', 8);//65585849
    ?>
    

    Edit

    After doing a collision/reliability test against my answer, its likely you will get collisions for length 8 and perhaps slightly less for 9 and then even less for 10 ect. In my test I tested an incrementing value from 0 to 100k and there were 26 collisions, the first happens a 36k.

    <?php 
    set_time_limit(0);
    header('Content-type: text/html; charset=utf-8');
    $time_start = microtime(true);
    
    function crc_string($str, $len){
        return substr(sprintf("%u", crc32($str)),0,$len);
    }
    
    echo 'Started, please wait...<br />';
    $record = array();
    $collisions = 0;
    for($i=0; $i<100000;$i++){
    
        $new = crc_string($i, 8);
        if(in_array($new,$record)){
            $match = array_search($new,$record);
            $took_time = microtime(true) - $time_start;
            echo($new.' has collided for iteration '.$i.' matching against a previous iteration ('.$match.') '.$record[$match]).' (Process time: '.round($took_time,2).'seconds)<br />';
            $collisions++;
        }else{
            $record[]=$new;
        }
    
        ob_flush();
        flush();
    }
    echo 'Successfully iterated 100k incrementing values and '.$collisions.' collisions occurred; total processing time: '.round((microtime(true) - $time_start),2).'seconds.';
    ?>
    

    Test result:

    Started, please wait...
    38862356 has collided for iteration 36084 matching against a previous iteration (8961) 38862356 (Process time: 165.47seconds)
    18911887 has collided for iteration 36887 matching against a previous iteration (8162) 18911887 (Process time: 172.79seconds)
    37462269 has collided for iteration 38245 matching against a previous iteration (33214) 37462269 (Process time: 185.81seconds)
    20153794 has collided for iteration 38966 matching against a previous iteration (6083) 20153794 (Process time: 192.87seconds)
    41429622 has collided for iteration 40329 matching against a previous iteration (24999) 41429622 (Process time: 206.41seconds)
    20784356 has collided for iteration 48908 matching against a previous iteration (27095) 20784356 (Process time: 302.75seconds)
    39932561 has collided for iteration 51926 matching against a previous iteration (12367) 39932561 (Process time: 340.88seconds)
    14372225 has collided for iteration 53032 matching against a previous iteration (13211) 14372225 (Process time: 355.46seconds)
    16636457 has collided for iteration 55490 matching against a previous iteration (39250) 16636457 (Process time: 389.44seconds)
    23059743 has collided for iteration 63126 matching against a previous iteration (39808) 23059743 (Process time: 504.1seconds)
    13627299 has collided for iteration 63877 matching against a previous iteration (21973) 13627299 (Process time: 516.08seconds)
    24647738 has collided for iteration 63973 matching against a previous iteration (47328) 24647738 (Process time: 517.62seconds)
    14471815 has collided for iteration 71118 matching against a previous iteration (37805) 14471815 (Process time: 641.93seconds)
    13253269 has collided for iteration 73602 matching against a previous iteration (33064) 13253269 (Process time: 687.53seconds)
    10732050 has collided for iteration 73706 matching against a previous iteration (9197) 10732050 (Process time: 689.44seconds)
    18919349 has collided for iteration 80358 matching against a previous iteration (73190) 18919349 (Process time: 819.89seconds)
    40795042 has collided for iteration 81875 matching against a previous iteration (31127) 40795042 (Process time: 851.3seconds)
    14609922 has collided for iteration 82498 matching against a previous iteration (17366) 14609922 (Process time: 864.29seconds)
    20425272 has collided for iteration 83914 matching against a previous iteration (9858) 20425272 (Process time: 894.32seconds)
    24790147 has collided for iteration 84519 matching against a previous iteration (9754) 24790147 (Process time: 907.34seconds)
    35605337 has collided for iteration 91434 matching against a previous iteration (36127) 35605337 (Process time: 1060.5seconds)
    30935494 has collided for iteration 91857 matching against a previous iteration (91704) 30935494 (Process time: 1070.17seconds)
    28520037 has collided for iteration 92929 matching against a previous iteration (28847) 28520037 (Process time: 1095.53seconds)
    31109474 has collided for iteration 95584 matching against a previous iteration (30349) 31109474 (Process time: 1159.36seconds)
    40842617 has collided for iteration 97330 matching against a previous iteration (13609) 40842617 (Process time: 1203.19seconds)
    20309913 has collided for iteration 99224 matching against a previous iteration (94210) 20309913 (Process time: 1250.54seconds)
    Successfully iterated 100k incrementing values and 26 collisions occurred; total processing time: 1269.98seconds.
    

    Conclusion is that unless you do a 1 for 1 increment on a auto incrementing value your always get collisions for the same byte length and more as you fill your users table:

    echo sprintf("%08d",'1');//00000001
    echo sprintf("%08d",'2');//00000002
    ...                      //99999999
    

    You can work around this by adding another byte to the collided value or include the a-z range like with md5()/sha() hash functions tho that defeats the object ;p

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anybody know of any small and simple ajax/php to do lists which I
I have installed Crystal Report by SAP for VS 2010. Does anybody know any
Does anybody have know any sample/tutorial (a sample server using SocketAsyncEventArgs etc) code about
Does anybody know any fine open source cube browser? Ideally, it would be something
Does anybody know any Ruby on Rails time_select plugins that have only one select
Does anybody know any way or any software which could decompile swf file to
Does anybody know any libraries of CL-procedures (it will be better if there is
does anybody know any css grid system with Base 980px Grid and Base 1003
Does anybody know any solution/walkaround to provide TLS/SSL support for TCP sockets in Silverlight
Does anybody know any tool for validating the syntax of an Regular Expression? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.