random alpha numeric string console log Math random toString 36 slice 2 function randomString len var p ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 return Array len reduce a a p Math random p length console log randomString 12 function keyGen keyLength var i key characters abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 var charactersLength characters length for i 0 i keyLength i key characters substr Math floor Math random charactersLength 1 1 return key console log keyGen 10 function generateUUID var d new Date getTime var uuid xxxxxxxx xxxx 4xxx yxxx xxxxxxxxxxxx replace xy g function c var r d Math random 16 16 0 d Math floor d 16 return c x r r 0x7 0x8 toString 16 return uuid toUpperCase console log generateUUID function ranCharLen charLen let res for let i 0 i charLen i res Math floor Math random 16 toString 16 return res console log ranCharLen 9
1 1 return key console log keyGen 10 function generateUUID var d new Date getTime var uuid xxxxxxxx xxxx 4xxx yxxx xxxxxxxxxxxx replace xy g function c var r d Math random 16 16 0 d Math floor d 16 return c x r r 0x7 0x8 toString 16 return uuid toUpperCase console log generateUUID function ranCharLen charLen let res for let i 0 i charLen i res Math floor Math random 16 toString 16 return res console log ranCharLen 9