Skip to content

Instantly share code, notes, and snippets.

@marknorgren
Forked from anonymous/index.html
Created July 23, 2015 18:19
Show Gist options
  • Save marknorgren/a7afa6d5eebedb49658d to your computer and use it in GitHub Desktop.
Save marknorgren/a7afa6d5eebedb49658d to your computer and use it in GitHub Desktop.
JS Bin javascript guid // source http://jsbin.com/movini
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="javascript guid">
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
function guid () {
function s4 () {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
console.log(guid());
</script>
<script id="jsbin-source-javascript" type="text/javascript">function guid () {
function s4 () {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
console.log(guid());</script></body>
</html>
function guid () {
function s4 () {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
console.log(guid());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment