JavaScript method for generating GUIDs

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.