Skip to content

Instantly share code, notes, and snippets.

@nahidakbar
Last active September 9, 2019 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahidakbar/c748195adc5d6127abd85c03a177351f to your computer and use it in GitHub Desktop.
Save nahidakbar/c748195adc5d6127abd85c03a177351f to your computer and use it in GitHub Desktop.
// 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