views:

128

answers:

5

Possible Duplicate:
How to create a GUID / UUID in Javascript?

I need to have a script that generates random numbers and letters with a form that looks like this:

M3KRT-CKKYV-YH4G4-YXP42-46FMT

Prefer jQuery, or javascript. I know how to generate number when the button is click using the .click() method in jQuery. But I can not find out how to actually make the code :(

A: 

Take a look at this link I found. With little modification you should get what you need:

http://www.frihost.com/forums/vt-40859.html

Jeff V
A: 

Modified this example a little:

http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript

And came up with this:

function S5() {
    return (((1 + Math.random()) * 0x100000) | 0).toString(16).substring(1);
}
function guid() {
    return (S5() + "-" + S5() + "-" + S5() + "-" + S5() + "-" + S5()).toUpperCase();
}
fehays
A: 

Try this out...

function createGuid () {
  for (var i=5, out=[]; i--;) {
    out.push((Math.random()*58786559+1679615|0).toString(36));
  }
  return out.join('-').toUpperCase();
}

alert(createGuid());
no
+1  A: 

Why do you include Win7 license key in your question?

Dmitry Gladkov
I thought it looked familiar... But this isn't an answer, it should be a comment on the question.
Benjamin Anderson
+1 for (some definition of) hack value
Marco Mariani