diceroll

Source ยป Wikipedia

Diceroll is a program used to generate random numbers with a few useless(-ish) features. This program takes advantage of Boost's program options library.

Program was tested with g++. To compile you may have to use -lboost_program_options. If you need to generate a load of random numbers, use -O3.

$ ./diceroll -h
Allowed options:

General options:
  -h [ --help ]                      produce this help message
  -p [ --precision ] arg (=21)       output precision (not internal precision)
  -q [ --quiet ]                     disable number output, useful with stats
  --list                             print numbers in a list
  --delim arg                        change the delimiter
  --numbers-force                    force the count of numbers printed to be
                                     equal to --number
  --flags                            print the flags

Internal RNG options:
  -n [ --number ] arg (=1)           count of numbers to be generated
  -l [ --lbound ] arg (=0)           minimum number (ldouble)
  -u [ --ubound ] arg (=1)           maximum number (ldouble)
  -g [ --generator ] arg (=mt19937)  change the RNG algorithm:
                                     minstd_rand0, minstd_rand
                                     mt19937, mt19937_64
                                     ranlux24_base, ranlux48_base
                                     ranlux24, ranlux48
                                     knuth_b, default_random_engine
                                     badrandom (std::rand)

Rounding options:
  -c [ --ceil ]                      apply ceiling function
  -f [ --floor ]                     apply floor function
  -r [ --round ]                     apply round function
  -t [ --trunc ]                     apply truncation

Matcher options:
  --exclude arg                      print only the numbers not exactly
                                     specified, best with rounding
  --include arg                      print only the numbers exactly specified,
                                     best with rounding
  --norepeat                         exclude repeated numbers from being
                                     printed, best with rounding
  --prefix arg                       only print if the number begins with
                                     string(s)
  --suffix arg                       only print if the number ends with
                                     string(s)
  --contains arg                     only print if the number contains
                                     string(s)

Statistics options:
  --stat-all                         print all statistics
  --stat-min                         print the minimum
  --stat-max                         print the maximum
  --stat-median                      print the median
  --stat-avg                         print the average
  --stat-var                         print the variance
  --stat-std                         print the standard deviation
  --stat-coef                        print the coefficient of variation

diceroll.cpp

Example

$ ./diceroll -p 5
0.27974
$ ./diceroll -n 100 -q --stat-all
min: 0.002179719051425401419
max: 0.977375478786662777462
median: 0.398437007011534366713
avg: 0.447476069991333935683
variance: 0.083249162000595136032
standard deviation: 0.288529308737596250502
coefficient of variation: 0.644792712028565160177
$ ./diceroll -n 10 --prefix 0.0001 --numbers-force
0.000107049545138513660
0.000143470444088610049
0.000147587322070482556
0.000139974264783565420
0.000181840486508422802
0.000160187321078831657
0.000162660698361068374
0.000128797573377098615
0.000174211224657959895
0.000110155040369495200

Why -g badrandom (std::rand) is bad:

$ for run in {1..3};do ./diceroll -n 2 -g badrandom;echo; done
0.735870394732742754155
0.633142639246370009752

0.735870394732742754155
0.633142639246370009752

0.735870394732742754155
0.633142639246370009752

$ for run in {1..3};do ./diceroll -n 2;echo; done
0.949858597491534347541
0.428885024200160522008

0.570460045097155726292
0.776410311903654044667

0.063175945874337505832
0.978945931156750787463