12.02.08

GUID generator in JavaScript

Posted in Open Source, Programming tagged , , , at 9:12 pm by Joshua

Found two little functions in JavaScript to create a GUID

function S4(){
return (((1+Math.random())*0×10000)|0).toString(16).substring(1);
}

function guid() {
return (S4()+S4()+”-”+S4()+”-”+S4()+”-”+S4()+”-”+S4()+S4()+S4());
}

Thanks to sj at note19.com, I don’t know exactly how reliable the generator is, I ran a couple tests against 50 guids, and it passed, but I need to run the guids through the Windows Installer using WiX, and I don’t know if there will be conflicts

I am still open to any other JavaScript generators if anyone knows of any

2 Comments »

  1. Mark Finkle said,

    Since your using Mozilla XPCOM, try nsIUUIDGenerator:
    http://mxr.mozilla.org/seamonkey/source/xpcom/base/nsIUUIDGenerator.idl

  2. Joshua said,

    Thanks Mark, it works perfectly

    I found a good example on MDC:
    https://developer.mozilla.org/en/NsIUUIDGenerator


Leave a Comment