PHP generates a random number example based on auto-incrementing data.
This article describes how to generate random numbers that are not repeated Based on Auto-increment data in PHP and share them with you for your reference. The following code is useless:
The key point is the number of auto-increment data digits generated.
The number of digits is controlled in two places.
1. $ base array. If the array is 8 bits, the array must be 8 bits.
2. $ I auto increment. The auto increment cannot exceed 8 digits.
The result of the current simple analysis is the above. We recommend that you use uuid or other methods if they are globally unique.
Sample Code:
Function swap ($ n, $ base) {$ mask = 19; // 1 + 2 + 16 $ n = intval ($ n, 10 ); $ idx = $ n & $ mask; // retrieve the flag bit $ xor = $ base [$ idx] ^ $ n; // locate the corresponding base based on the ID, xor or n return ($ xor | $ mask) ^ $ mask) | $ idx; // overwrite the identification space} $ newArray = []; $ base = array (0 => 1918407, 1 => 5529570, 2 => 6527234, 3 => 6550962, 4 => 8054672, 5 => 3141234, 6 => 2125630, 7 => 6978033, 8 => 4623630, 9 => 4736420, 10 => 7767295, 11 => 9679880, 12 => 1665600, 13 => 6044373, 14 => 4661383, 15 => 5771843, 16 => 2206123, 17 => 5685396, 18 => 5571647, 19 => 7178311,); for ($ I = 0; $ I <1000000; $ I ++) {$ newArray [] = swap ($ I, $ base ). "\ r \ n ";}
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.