I found the question here:
Create GUID / UUID in JavaScript?
The answer provides the following JS:
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
Now, Some of this seems silly to me. Why so much repetition? I planned on using this to name file being uploaded to my server so that they didn't override each other. This doesn't look like it will always generate a unique number.
What is the above codes benefit over just naming the file math.random()
. It doesn't even change the seed.
Sorry, I've never worked with GUID / UUID ever and some of the code doesn't really make any sense to me...
CLARIFICATION
A lot of people aren't answering the question like I asked it. A lot of people are explaining that GUID isn't always unique, blah blah blah. That isn't what I'm asking. I'm asking, what was the point of using it over just math.random()
.
Joe seems to have given the best answer for me in the comments.