1function randomId(): string {
2 const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
3 return uint32.toString(16);
4}
1function uuidv4() {
2 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
4 return v.toString(16);
5 });
6}
7
8console.log(uuidv4());
1function uuid() {
2 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
3 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
4 return v.toString(16);
5 });
6}
7
8var userID=uuid();//something like: "ec0c22fa-f909-48da-92cb-db17ecdb91c5"
1const uid = () => {
2 return Date.now().toString(36) + Math.random().toString(36).substr(2);
3};
4
5// Usage. Example, id = khhry2hb7uip12rj2iu
6const id = uid();