A dual-Shot class that is completely mapped to one-to-one in a given natural number space. It is reversible and cannot be guessed.

Source: Internet
Author: User
Using the principles of mass numbers and modulo operations, a given natural number space maps each natural number to another natural number, and the mapped natural number is mapped only by this natural number. It is mainly used to generate the natural number corresponding to the unguessed natural number that is evenly distributed in the natural number space corresponding to the auto-increment id. It is used for resource URIs with privacy protection such as express logistics bill number, order number, and image path.

Using the principles of mass numbers and modulo operations, a given natural number space maps each natural number to another natural number, and the mapped natural number is mapped only by this natural number. It is mainly used to generate the natural number corresponding to the unguessed natural number that is evenly distributed in the natural number space corresponding to the auto-increment id. It is used for resource URIs with privacy protection such as express logistics bill number, order number, and image path.

Using the principles of mass numbers and modulo operations, a given natural number space maps each natural number to another natural number, and the mapped natural number is mapped only by this natural number.
It is mainly used to generate the natural number corresponding to the unguessed natural number that is evenly distributed in the natural number space corresponding to the auto-increment id.
It is used for resource URIs with privacy protection such as express logistics bill number, order number, and image path.
<无>
/***** Double-shot class * completely maps one to one in a given natural number space, reversible operation, cannot be guessed * @ author liuxu **/class Bijective {static private $ defaultPrime = '000000 '; // use the prime number static public function getRandPrime () {return self: getMinPrime (rand (,) with a single digit of "3", "7", and "9) * 100000 + rand (100000,900000);} static public function getMinPrime ($ min) {$ number = $ min; while (true) {if (self :: isPrime ($ number) break; $ number ++;} return $ number;} static public function isPrime ($ number) {$ sqrt = intval (bcsqrt ($ number, 0); for ($ I = 2; $ I <= $ sqrt; $ I ++) {if (bcmod ($ number, $ I) === '0') {return false ;}} return true;} static public function mod ($ number, $ len = 10) {return bcmod (bcmul ($ number, self: $ defaprime Prime, 0), bcpow (10, $ len, 0);} static public function loop ($ number, $ len = 8) {$ min = $ prev = $ number; for ($ I = 1; $ I ++) {$ next = self: mod ($ prev, $ len ); if ($ next = $ number) break; $ min = min ($ min, $ next); $ prev = $ next;} $ offset = ($ min % $ I) + 1; for ($ j = 0; $ j <$ offset; $ j ++) {$ number = self: mod ($ number, $ len );} return $ number;} static public function insanity ($ number, $ len = 10) {$ number = self: mod ($ number, $ len ); $ number = str_pad ($ number, $ len, '0', STR_PAD_LEFT); $ numberList = str_split ($ number, 6 ); foreach ($ numberList as $ key => $ value) {$ numberList [$ key] = str_pad (self: loop ($ value, strlen ($ value )), strlen ($ value), '0', STR_PAD_LEFT);} $ number = implode ('', $ numberList); return $ number ;}}

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.