Skip to content

Instantly share code, notes, and snippets.

@Shuumatsu
Created November 13, 2017 12:37
Show Gist options
  • Save Shuumatsu/740b69e4a01a3a7c6eb7be98176fa4de to your computer and use it in GitHub Desktop.
Save Shuumatsu/740b69e4a01a3a7c6eb7be98176fa4de to your computer and use it in GitHub Desktop.
const seenKeys = new Set()
const MULTIPLIER = Math.pow(2, 24)
const generateRandomKey = () => {
const key = Math.floor(Math.random() * MULTIPLIER).toString(32)
if (seenKeys.has(key) || !isNaN(+key))
return generateRandomKey()
seenKeys.add(key)
return key
}
module.exports = randomKey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment