Last active
September 9, 2019 23:45
-
-
Save nahidakbar/c748195adc5d6127abd85c03a177351f 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
// produces unique enough base36 serial based on nanosecond time | |
function makeUpgradeCode() { | |
const [nanoseconds, seconds] = process.hrtime(); | |
const time = (seconds * 1e6 + nanoseconds) | |
.toString(26) | |
.split('') | |
.map(x => (parseInt(x, 26) + 10).toString(36)) | |
.concat(Math.random().toString(10).substring(2).split('')) | |
.slice(0, 12); | |
const [a, b, c, d, e, f, g, h, i, j, k, l] = time; | |
return `${l}${h}${d}-${i}${e}${a}-${f}${b}${j}-${c}${k}${g}`; | |
} | |
// const codes = {}; | |
// for (let x = 0; x < 100000; x++) { | |
// const code = makeUpgradeCode(); | |
// if (codes[code]) { | |
// console.log(code); | |
// } | |
// codes[code] = true; | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment