Created
November 8, 2018 13:45
-
-
Save craigmulligan/b917d65c1563608df5ee5c1d38821dcf to your computer and use it in GitHub Desktop.
frame number generator
This file contains 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 mod10CheckDigit = require('mod10-check-digit') // single digit check digit | |
const scheme_id = 1 | |
const generation_id = 1 | |
const totalbikes = 15 | |
const cache = [] | |
function getRandomInt() { | |
return Math.floor(Math.random() * 90 + 10) | |
} | |
function generate() { | |
const n = `${scheme_id}${generation_id}${getRandomInt()}` | |
const check_num = mod10CheckDigit(n).toString() | |
return `${n}${check_num}` | |
} | |
while (cache.length != totalbikes) { | |
const frame_number = generate() | |
if (!cache.includes(frame_number)) { | |
console.log(frame_number) | |
cache.push(frame_number) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment