feat: add CLI random number generator supporting 6 distributions
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
export const HELP = `rand — Generate random numbers
|
||||
|
||||
Usage:
|
||||
rand [options] [args]
|
||||
|
||||
Options:
|
||||
-c, --count <n> Number of random numbers to output (default: 1)
|
||||
-f[N] Decimal places: -f = -f2 (default: 2)
|
||||
--float [N] Long form of -f
|
||||
-d, --dist <name> Distribution (default: uniform)
|
||||
-h, --help Show this help
|
||||
|
||||
Distributions and their positional args:
|
||||
uniform rand [min] [max] (default: 0 100)
|
||||
normal rand -d normal [mean] [stddev] (default: 0 1)
|
||||
binomial rand -d binomial [n] [p] (default: 10 0.5)
|
||||
poisson rand -d poisson [lambda] (default: 1)
|
||||
exponential rand -d exponential [lambda] (default: 1)
|
||||
hypergeometric rand -d hypergeometric [N] [K] [n]
|
||||
(default: 100 50 10)
|
||||
|
||||
Examples:
|
||||
rand # uniform 0–100
|
||||
rand -d normal # normal μ=0, σ=1
|
||||
rand -d normal 100 15 -f1 # normal μ=100, σ=15, 1 decimal
|
||||
rand -d binomial 20 0.3 -c 5 # 5 binomial(n=20, p=0.3)
|
||||
rand -d poisson 3 # poisson λ=3
|
||||
rand -d exponential 0.5 # exponential λ=0.5
|
||||
echo "5 2" | rand -d normal # stdin overrides positional args
|
||||
rand | xargs echo # pipe output`;
|
||||
|
||||
export function showHelp(): never {
|
||||
console.log(HELP);
|
||||
process.exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user