Method One:
? PHP
$str = uniqid (Mt_rand (), 1);
Echo ' SHA1: ', SHA1 ($STR);
Echo ' <br> ';
Echo ' MD5: ', MD5 ($STR);
Using Uniqid function, with Mt_rand random function, finally using hash is worth the final unique value.
But in the test, the uniqueness of the random number was found to be somewhat the same, with approximately 11 identical (but no serious)
Second method: GUID
? PHP echo sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ', mt_rand ( 0, 65535), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (16384, 20479), mt_rand (32768, 49151), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0,
65535));
echo "<br>"; echo sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ', mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (16384, 20479), mt_ Rand (32768, 49151), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0, 65535)
);
echo "<br>"; echo sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ', mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (16384, 20479), Mt_rand (32768, 49151), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0,
65535));
echo "<br>"; echo sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ', mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (16384, 20479), mt_ Rand (32768, 49151), mt_rand (0, 65535), mt_rand (0, 65535), mt_rand (0, 65535)
); ?>
Example 3
<?php
//using uniqid Mt_rand to generate random, repetitive strings
$snKeys =array ();
$total =10;//Set the build quantity
$prefix = ' code ';//String prefix while
(count ($snKeys) < $total) {
$snKeys [$prefix. MD5 ( Uniqid (Mt_rand (), true)] = null;
}
Print_r ($snKeys);