Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Created March 14, 2024 21:19
Show Gist options
  • Save Angelfire/3fbc9debefcb4f1154fb9db7b04c95e5 to your computer and use it in GitHub Desktop.
Save Angelfire/3fbc9debefcb4f1154fb9db7b04c95e5 to your computer and use it in GitHub Desktop.
Generates a random ID with the given prefix.
/**
* Generates a random ID with the given prefix.
* @param prefix - The prefix to be added to the generated ID.
* @returns The generated random ID.
*/
export const generateRandomId = (prefix: string) =>
`${prefix}${btoa(Date.now().toString())}${btoa(
(Math.random() * 1_000_000_000_000).toString()
)}`.replace(/=+/g, "");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment