GUID (Globally Unified Identifier) refers to a number generated on a machine that is guaranteed to be unique to all machines in the same time and space. Usually the platform will provide an API to generate GUID. The generation algorithm is interesting, using the Ethernet card address, nanosecond time, chip ID and many possible numbers. The only drawback of GUID is that the resulting string will be relatively large.
The format of GUID is: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Everyone knows that GUID is not very useful in front-end development, but if you need to insert an ID, and this ID corresponds to the backend and other operations that require a GUID, we can still generate a GUID for convenience.
Generally, it is very simple to generate GUID in backend or database languages such as sql, java, C#, etc. However, there is no way to directly generate GUID on the front end, so you can only write one by yourself. But because the GUID needs to obtain the address of the Ethernet card, as well as nanosecond-level time and other numbers. It is difficult for the front-end to obtain this information (please tell me if you know it), but we can simulate and generate GUID, the code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
GUID Object
Just save it in a JS file and reference it.
Then we just need to.
alert(guid.newGUID());
The implementation principle is very simple. Here we just use the system time and more than 18 hexadecimal random numbers, and convert the system time into hexadecimal. Although it is still possible to repeat, the probability of repetition is extremely low. , can be ignored.
The above method is written by me to generate GUID. If you have a better method, please tell me, thank you!