Skip to content

Instantly share code, notes, and snippets.

@ucpwang
Last active December 13, 2017 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ucpwang/9636b5efc47b72ab3cd50384946c0c43 to your computer and use it in GitHub Desktop.
Save ucpwang/9636b5efc47b72ab3cd50384946c0c43 to your computer and use it in GitHub Desktop.
javascript GUID

javascript GUID

const makeGUID = () => {
  const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
  return `${s4()}${s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`;
}
> makeGUID();
< "3e41f370-a0ce-b12b-6b88-eb0e88ff36ad"
> makeGUID();
< "91837567-aeea-bdea-682d-5734cb138a46"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment