first, the method of generating a GUIDJScript CodeCopy
{ { 1+math.random () *0x10000)-|-((()). ToString (+). substring (1); } Return (S4 () +s4 () + "-" +s4 () + "-" +s4 () + "-" +s4 () + "-" +s4 () +s4 () +s4 ());}
Second, the method of generating GUID two
JScript CodeCopy
{ { var r = math.random () *16|0, v = c = = ' X ' r: (r&0x3|0x8); return v.tostring (+); });
Third, the method of generating the GUID three
JScript CodeCopy
{ var s = []; var hexdigits = "0123456789abcdef"; { S[i] = Hexdigits.substr (Math.floor (Math.random () * 0x10), 1); } S[14] = "4"; Bits 12-15 of the Time_hi_and_version field to 0010 s[19] = Hexdigits.substr ((s[19] & 0x3) | 0x8, 1); Bits 6-7 of the clock_seq_hi_and_reserved to s[8] = s[13] = s[18] = s[23] = "-"; var uuid = S.join (""); return uuid;}
Iv. method of generating GUIDs four
JScript CodeCopy
function uuid (len, Radix){var chars = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '. Split ('); var uuid = [], I; Radix = Radix | | Chars.length; if (len) {//Compact form for (i = 0; i < len; i++) Uuid[i] = chars [0 | Math.random () *radix]; } else {//rfc4122, version 4 form var R; rfc4122 requires these characters uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; UUID[14] = ' 4 '; Fill in random data. At i==19 set the high bits of clock sequence AS//per rfc4122, Sec. 4.1.5 for (i = 0; i <; i++) {if (!uuid[i]) {r = 0 | Math.random () *16; Uuid[i] = chars[(i = = 19)? (R & 0x3) | 0X8:R]; }}} return Uuid.join (");}
How JavaScript generates GUIDs