Related Post

3 Comments Received

February 11th, 2010 @2:23 pm  

The term 0×10000 in function s4() seems to be the source of error in my use of the proposed javascript GUID creator. Here is my proposed solution:

Untitled Document

function S4() {
// replace 0×10000 with this format: *parseInt(’10000′,16); RDF
return ((1+Math.random())*parseInt(’10000′,16)).toString(16).substring(1);
}
function generateGuid(){
return (S4()+S4()+”-”+S4()+”-”+S4()+”-”+S4()+”-”+S4()+S4()+S4()).toUpperCase();
}

// test the GUID generator
alert(generateGuid());

February 11th, 2010 @2:52 pm  

Oops, I have two more fixes to make the GUID a little more usable and a little more random…

Untitled Document

function S4() {
// add a seed to randome number generator, RDF
now = new Date();
seed = now.getSeconds();
// replace 0×10000 with this format: *parseInt(’10000′,16); RDF
// replace substring(1) with a 4 digit hex string like this: substring(1,5); RDF
return ((1+Math.random(seed))*parseInt(’10000′,16)).toString(16).substring(1,5);
}
function generateGuid(){
return (S4()+S4()+”-”+S4()+”-”+S4()+”-”+S4()+”-”+S4()+S4()+S4()).toUpperCase();
}

// test the GUID generator
document.writeln(generateGuid());

February 11th, 2010 @2:55 pm  

I made a few more fixes…

Untitled Document

function S4() {
// add a seed to randome number generator, RDF
now = new Date();
seed = now.getSeconds();
// replace 0×10000 with this format: *parseInt(’10000′,16); RDF
// replace substring(1) with a 4 digit hex string like this: substring(1,5); RDF
return ((1+Math.random(seed))*parseInt(’10000′,16)).toString(16).substring(1,5);
}
function generateGuid(){
return (S4()+S4()+”-”+S4()+”-”+S4()+”-”+S4()+”-”+S4()+S4()+S4()).toUpperCase();
}

// test the GUID generator
document.writeln(generateGuid());

Leave A Reply

Please Note: Comments maybe under moderation after you submit your comments so there is no need to resubmit your comment again