Unique Code Random Code
The more specific needs are this
The database may gradually insert no more than 10w records, want to add a field, each record of the value of this field is a 8-bit code
1. It looks like a random code, like Dlkpownd Ouichgeb.
2. Can not be "easy" to crack such as id=1 corresponding to the aaaaaaaa id=2 corresponding Aaaaaaab of course, this description may be repeated with the first one anyway is to the other side can not easily guess a code to find the result (10W corresponds to 208.8 billion kinds of possible, If only by guessing basically can't hit).
3. Want to be able to get such a code before inserting this record into the input library and do not need to retrieve whether the database already exists. This one may not be clear enough for me to describe: In fact I can use the substr (rand (0,25), 1, $str) loop eight times to generate a code, Then go to the database to find, if not yet, insert, so it is unique. But this is the last option, and hopefully, the time stamp like MD5 can generate a unique rather than a database to determine whether it is unique. Timestamps are just an example, not necessarily a time stamp for seeding.
This is basically the case, if not clear can be put forward I add. Ask for ideas or give a method ~ ~ Thank you
Reply to discussion (solution)
Up to 100,000 bars?
Which means that the self-increment ID is 1 to 99999.
Press 5 bits to complement the leading 0, i.e. 00001 to 99999
Append the digits (of course you specified) to 000011 to 999999
and do base64 code.
echo base64_encode (' 000011 '), Php_eol;echo base64_encode (' 999999 '), php_eol;/*mdawmdexotk5otk5*/
If necessary, do "Caesar encryption" on the results (dictionary shift)
The self-increment ID is unique, so getting a string is also unique
The algorithm should be very simple.
Seeding with a self-increment ID is a good choice because it is unique within the range of 10w and the current timestamp after eight bits is not
But this is not to be deposited first, get ID sour code and then update to the database? Can you check the database or write the database before you get the code or insert the code that meets the requirements?
Since it is a morph ID, there is no need to save it in the library?
Do a inverse do not restore it?
Seeding with a self-increment ID is a good choice because it is unique within the range of 10w and the current timestamp after eight bits is not
But this is not to be deposited first, get ID sour code and then update to the database? Can you check the database or write the database before you get the code or insert the code that meets the requirements?
Base64_encode (Base_convert (Time (), 10, 36));
Convert the current time to 36 (8 digits), in the use of Base64_encode encryption can not, to ensure that the only, and do not check the database.
Time is also a way, but the light is not good.
Who can guarantee that two requests are not answered in the same second?
Maybe it works.
Echo Base_convert (Str_replace ('. ', ' ', $_server[' request_time_float ']), 10, 36);
But accurate to milliseconds, it may be a problem for high-performance servers
Define (' Only ', ' Fdsar2432fds ');
Echo Base64_encode (only. ' 000011 '), Php_eol;
Echo Base64_encode (only. ' 999999 '), Php_eol;