Skip to content

fairhive-labs/generate_6digits_code

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

generate_6digits_code

Small Node.js CLI for generating zero-padded numeric codes with cryptographically secure randomness.

Runtime

This project targets Node.js 24 LTS. Use .nvmrc with nvm use, or install any 24.x release.

Install

Global install:

npm install -g @poln/gen6dcode

Run without installing:

npx @poln/gen6dcode

Usage

Generate the default 6-digit code:

gen6dcode

Generate a custom length:

gen6dcode --digits 8
gen6dcode -d 20

Generate JSON output:

gen6dcode --json
gen6dcode --json --digits 8

Show help:

gen6dcode --help

Example output:

gen6dcode v3.1.0
+---------------------------+
| digits : 6                |
| code   : 482913           |
+---------------------------+

JSON output:

{"name":"@poln/gen6dcode","version":"3.1.0","digits":6,"code":"482913"}

Rules

  • Supported digit range: 1 to 20
  • Output is always zero-padded to the requested length
  • Invalid input exits with code 1

Example invalid input:

gen6dcode -d 0
# --digits must be an integer between 1 and 20

Why this version is safer

Older implementations based on Math.random() and floating-point math can produce biased output and become inaccurate at higher digit counts. This package now uses Node's crypto module, including a secure fast path for smaller codes and exact BigInt-based generation for larger ones.

Local development

npm install
nvm use
npm start
npm start -- --digits 12
npm test

About

generate 6 digits code

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%