Skip to content

Instantly share code, notes, and snippets.

@craigmulligan
Created November 8, 2018 13:45
Show Gist options
  • Save craigmulligan/b917d65c1563608df5ee5c1d38821dcf to your computer and use it in GitHub Desktop.
Save craigmulligan/b917d65c1563608df5ee5c1d38821dcf to your computer and use it in GitHub Desktop.
frame number generator
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