Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 1

GUID in JavaScript

Its easy to make GUIDs in JavaScript. Below is code to get strings that look like GUIDs. This
code just random GUIDs they are not claimed to be unique. Don't use these if its very
important.
1function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
2
}
3
4// then to call it, plus stitch in '4' in the third group
5guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() +
6"-" + S4() + S4() + S4()).toLowerCase();
7alert(guid);
Try it out now!
code thanks to: BYTES These guys are so GUID they UUed my ID.
A heavy duty version that meets the GUID standards can be found here.

You might also like