uuid
function uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } console.log(uuidv4());
Here is what the above code is Doing:
1. We’re using the uuidv4() function to generate a random string.
2. We’re using the replace() method to replace the x and y characters with a random hexadecimal number.
3. We’re using the Math.random() method to generate a random number.
4. We’re using the toString() method to convert the random number to a string.
5. We’re using the toString(16) method to convert the random number to a hexadecimal string.