php-generating a unique ID string

Source: Internet
Author: User

1. Generate a unique ID

Uniqid ();//without prefix, the generated string is 13 bits, according to the current subtle timestamp

2. Random functions

/**
* Generate a random string of the specified number of digits
*
* @param int $len random string length
* @param bool $include _number is allowed to contain numbers
*
*/

public static function make_rand_string ($len, $include _number = False) {
$string _list = Array (' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' J ', ' K ', ' L ', ' M ', ' N ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ' , ' f ', ' g ', ' H ', ' J ', ' K ', ' m ', ' n ', ' P ', ' Q ', ' R ', ' s ', ' t ', ' u ', ' V ', ' w ', ' x ', ' y ', ' z ');

$string _include_number_list = Array (' A ', ' B ', ' C ', ' D ', ' E ', ' F ', ' G ', ' H ', ' J ', ' K ', ' M ', ' N ', ' P ', ' Q ', ' R ', ' S ', ' T ', ' U ', ' V ', ' W ', ' X ', ' Y ', ' Z ', ' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' g ', ' H ', ' J ', ' K ', ' m ', ' n ', ' P ', ' Q ', ' R ', ' s ', ' T ', ' U ', ' V ', ' w ', ' x ', ' y ', ' z ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ');

if ($include _number) {
$arr = $string _include_number_list;
} else {
$arr = $string _list;
}

$rand _max = count ($arr)-1;
$return _string = null;

for ($i = 0; $i < $len; $i + +) {
$rand = Mt_rand (0, $rand _max);
$return _string. = $arr [$rand];
}

return $return _string;

}

3. Write a blog to keep the chaos

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.