how is create a unique tracking code [closed]

2019-01-20 20:24发布

问题:

how can create a unique tracking code?
What is your suggestion?

The number of characters not more than 10 and use only of number .
Please call example powerful...

回答1:

If you're willing to allow for a few more characters, and let your number be a hex number, the uniqid function will be useful to you



回答2:

How about using time();?? It will give exactly 10digits and will be unique forever with a difference of microseconds:)



回答3:

Because of maximum random number limits, you might use something like this:

$number = mt_rand(10000,99999).mt_rand(10000,99999);

Or use for loop as @JK posted. Then, you might check uniquiness of the number, and, if not unique, generate new...



回答4:

$random = "";
for($i = 0; $i < 10; $i++)
  $random .= mt_rand(0, 9);

However if you want something more powerful you should consider using characters as well:

$random = substr(base64_encode(sha1(mt_rand())), 0, 10);