Skip to content

Instantly share code, notes, and snippets.

@stefanfrede
Created January 15, 2020 12:42
Show Gist options
  • Save stefanfrede/73e7dff5611e3f4101babf5bc78d6281 to your computer and use it in GitHub Desktop.
Save stefanfrede/73e7dff5611e3f4101babf5bc78d6281 to your computer and use it in GitHub Desktop.
Generate a unique id in the browser without a library
function randomId() {
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
return uint32.toString(16);
}
const rid = randomId();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment