Skip to content

Instantly share code, notes, and snippets.

@otofune
Last active March 6, 2017 09:07
Show Gist options
  • Save otofune/0f682b27c41dfa2f5c65a29b9677be83 to your computer and use it in GitHub Desktop.
Save otofune/0f682b27c41dfa2f5c65a29b9677be83 to your computer and use it in GitHub Desktop.
アホUUIDジェネレーター
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