1var ID = function () {
2 // Math.random should be unique because of its seeding algorithm.
3 // Convert it to base 36 (numbers + letters), and grab the first 9 characters
4 // after the decimal.
5 return '_' + Math.random().toString(36).substr(2, 9);
6};
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"
1let ID = (length = 6) => {
2 // new Date() will return current time
3 // getTime() method returns the number of milliseconds* since the Unix Epoch.
4 // -length to get last items on string
5 return new Date().getTime().toString().slice(-length);
6}