Skip to content

Instantly share code, notes, and snippets.

@mjethani
Last active March 7, 2016 13:24
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 mjethani/89950960d4be3ae26215 to your computer and use it in GitHub Desktop.
Save mjethani/89950960d4be3ae26215 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// usage: passcode [<length>]
var crypto = require('crypto')
function randomPasscode(length) {
var passcode = ''
for (var i = 0; i < length; i++) {
passcode += Math.floor(crypto.randomBytes(1).readUInt8() * 10 / 0x100)
}
return passcode
}
function main() {
if (process.argv[2] === '--help' || process.argv[2] === '-h' ||
process.argv[2] === '-?') {
console.log('usage: passcode [<length>]\n')
process.exit()
}
console.log(randomPasscode(+process.argv[2] || 11))
}
if (require.main === module) {
main()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment