Last active
March 6, 2017 09:07
-
-
Save otofune/0f682b27c41dfa2f5c65a29b9677be83 to your computer and use it in GitHub Desktop.
アホUUIDジェネレーター
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uuid = () => { | |
const random = (range = 16) => Math.floor(Math.random() * range); | |
const hexadecimal = num => num.toString(16); | |
const array = new Array(30).fill().map(() => hexadecimal(random())); | |
const slice = (x,y) => array.slice(x,y).join(''); | |
const pack = (delimiter, ...content) => content.join(delimiter); | |
return pack('-', | |
slice(0,8), | |
slice(8,12), | |
'4' + slice(12,15), | |
hexadecimal(random(3) + 8) + slice(15,18), | |
slice(18,30)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment