JavaScript generation uuid (Method 1)

Source: Internet
Author: User

You can create a UUID directly online, preview it,

This site is good, you can choose the UUID version, you can also directly remove the underline, easy to use Ah, haha
http://www.uuid.online/

  

/*! Math.uuid.js (v1.4) http://www.broofa.commailto:[email protected] Copyright (c) Robert kiefferdual licensed Under the MIT and GPL licenses.*//* * Generate a random uuid. * * USAGE:MATH.UUID (length, radix) * Length-the desired number of characters * radix-the number of allowable Val UEs for each character. * * EXAMPLES: *//No arguments-returns RFC4122, version 4 ID * >>> math.uuid () * "92329d39-6f5c-4520-ab fc-aab64544e172 "* *//One argument-returns ID of the specified length * >>> math.uuid (All)//Chara Cter ID (default base=62) * "VCYDXGLTXRVZSTV" * *///arguments-returns ID of the specified length, and radix. (Radix must be <=) * >>> Math.uuid (8, 2)//8 character ID (base=2) * "01001010" * >>> Math   . UUID (8, ten)//8 character ID (base=10) * "47473046" * >>> Math.uuid (8, +)//8 character ID (base=16) * "098f4d35" */(function () {//Private array of chars to use VAr CHARS = ' 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '. Split (');    Math.uuid = function (len, radix) {var chars = chars, 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 (");   };  A more performant, but slightly bulkier, rfc4122v4 solution. We boost performance//by minimizing calls to random () Math.uuidfast = function () {var chars = chars, uuid = new Ar Ray (rnd=),0, R;  for (var i = 0; i < i++) {if (i==8 | | i==13 | | i==18 | |      i==23) {Uuid[i] = '-';      } else if (i==14) {uuid[i] = ' 4 ';        } else {if (rnd <= 0x02) rnd = 0x2000000 + (math.random () *0x1000000) |        r = rnd & 0xf;        Rnd = Rnd >> 4; Uuid[i] = chars[(i = = 19)? (R & 0x3) |      0X8:R];  }} return Uuid.join (");   }; A more compact, but less performant, rfc4122v4 solution:Math.uuidCompact = function () {return ' xxxxxxxx-xxxx-4xxx      -yxxx-xxxxxxxxxxxx '. Replace (/[xy]/g, function (c) {var r = math.random () *16|0, v = c = = ' X ' r: (r&0x3|0x8);    return v.tostring (16);  }); };}) ();

  

Calling method: Math.uuid ()

JavaScript generation uuid (Method 1)

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.