Created
March 16, 2022 00:51
-
-
Save gkweb/b2d1fb1c7281bad35c4b3487e834bd5d to your computer and use it in GitHub Desktop.
Medicare 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 fs = require('fs') | |
// Grabbed from here: https://gist.github.com/Ugrend/09890dbc7a049651d470d1f8b6b73e1a | |
function randomMedicareNumber(): string { | |
let sum = Math.floor(Math.random() * 5) + 2 | |
const weights = [1, 3, 7, 9, 1, 3, 7, 9] | |
const num = [sum] | |
for (let i = 0; i < 7; i++) { | |
const n = Math.floor(Math.random() * 10) | |
sum += n * weights[i + 1] | |
num.push(n) | |
} | |
num.push(sum % 10) | |
return num.join('') + '1/1' | |
} | |
/** | |
* Generates many medicare card numbers. Used for development purposes only. | |
* Writes to file: medicare-numbers.json | |
* @param amount | |
*/ | |
function generateMany(amount = 1000 as number): void { | |
const seed = new Array(amount).fill(undefined) | |
const many = seed.map(() => { | |
const r = randomMedicareNumber() | |
return r | |
}) | |
console.log(JSON.stringify(many)) | |
fs.writeFileSync('medicare-numbers.json', JSON.stringify(many)) | |
} | |
generateMany() | |
/** Usage: npx node-ts --inspect generate-medicare-card-number.ts */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment