The short 8-bit UUID idea actually draws on the microblog short domain name generation way, but its repetition probability is too high, and each time generates 4, needs to select one immediately.
The algorithm uses 62 printable characters, randomly generated 32-bit UUID, because the UUID is 16, so the UUID is divided into 8 groups, each 4 is a group, and then through the modulo 62 operation, the result as an index to remove characters,
So the repetition rate is greatly reduced.
After testing, there was no duplication in generating 10 million data, which fully met most of the requirements.
The code is posted for everyone's reference.
public static string[] chars = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "n", "O", "P", "Q", "R", "s", "T", "U", "V", "W", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" &NBSP;};p ublic static string generateshortuuid () { stringbuffer shortbuffer = new stringbuffer (); String uuid = uuid.randomuuid (). toString (). Replace ("-", ""); for (int i = 0; i < 8; i++) { string str = uuid.substring (I&NBSP;*&NBSP;4,&NBSP;I&NBSP;*&NBSP;4&NBSP;+&NBSP;4); int x = integer.parseint (str, 16); shortbuffer.append (chars[x % 0x3e]); } return shortbuffer.tostring ();}
JAVA generates no repeat 8-bit random code