Created
November 13, 2017 12:37
-
-
Save Shuumatsu/740b69e4a01a3a7c6eb7be98176fa4de to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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