Skip to content

Instantly share code, notes, and snippets.

@andrew8088
Last active October 28, 2019 13:58
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 andrew8088/ee33150326aacb02763af3326f1f08d4 to your computer and use it in GitHub Desktop.
Save andrew8088/ee33150326aacb02763af3326f1f08d4 to your computer and use it in GitHub Desktop.
Generate Request Id
const now = () => {
const [sec, nano] = process.hrtime();
return sec * 1e9 + nano;
};
const rand = () => Math.floor(Math.random() * 1e16);
const getRequestId = () =>
(now() + rand())
.toString(16)
.substr(0, 12)
.toUpperCase();
@andrew8088
Copy link
Author

This will generate IDs like this:

1FEDAE1BFDEB
3611D6EA57BC
123A06E3EC45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment