JavaScript generation uuid (Method 2)

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/

On creation of a UUID object, set it ' s initial valuefunction UUID () {this.id = This.createuuid ();} When asked what's this Object is, lie and return it ' s valueUUID.prototype.valueOf = function () {return this.id;}; UUID.prototype.toString = function () {return this.id;};////INSTANCE Specific methods//uuid.prototype.createuuid = function () {////Loose Interpretation of the specification DCE 1.1:remote Procedure call//since JavaScript do ESN ' t allow access to internal systems, the last bits per//Of the node section was made up using a series of random num    Bers (6 octets long).    var dg = new Date (1582, 10, 15, 0, 0, 0, 0);    var dc = new Date ();    var t = dc.gettime ()-dg.gettime ();    var tl = uuid.getintegerbits (t,0,31);    var TM = uuid.getintegerbits (t,32,47); var THV = uuid.getintegerbits (t,48,59) + ' 1 ';    Version 1, security version is 2 var csar = Uuid.getintegerbits (Uuid.rand (4095), 0,7);   var CSL = Uuid.getintegerbits (Uuid.rand (4095), 0,7); Since detection of anything about the Machine/browser are far from buggy,//include some more random numbers here    If NIC or an IP can is obtained reliably, that should is put in//here instead. var n = uuid.getintegerbits (Uuid.rand (8191), 0,7) + uuid.getintegerbits (Uuid.rand (8191), 8,15) + UUID. Getintegerbits (Uuid.rand (8191), 0,7) + uuid.getintegerbits (Uuid.rand (8191), 8,15) + uuid.getintegerbit S (Uuid.rand (8191), 0,15); This last number is a octets long return TL + TM + THV + CSAR + CSL + n;};/ /pull out-certain bits from a very large integer, used to get the Time//code information for the first part of a UUID . Would return Zero's if There//aren ' t enough bits to shift the where it needs to.    Uuid.getintegerbits = function (val,start,end) {var base16 = uuid.returnbase (val,16);    var quadarray = new Array ();    var quadstring = ';    var i = 0; for (i=0;i<base16.length;i++) {Quadarray.push (base16.substring (i,i+1)); } for (I=math.floor (START/4); I<=math.floor (END/4); i++) {if (!quadarray[i] | | quadarray[i] = = ") Quadstring + =        ' 0 ';    else quadstring + = Quadarray[i]; } return quadstring;};/ /replaced from the original function to leverage the built in methods In//javascript. Thanks to Robert Kieffer for pointing this one outuuid.returnbase = function (number, base) {return (number). toString (BA SE). toUpperCase ();};/ /pick a random number within a range of Numbers//int b rand (int a); where 0 <= b <= auuid.rand = function (max) {return Math.floor (Math.random () * (max + 1));};

Calling method: UUID.prototype.createUUID ()

JavaScript generation uuid (Method 2)

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.