Decide

by John Walker


A just machine to make big decisions
Programmed by fellows with compassion and vision.

— Donald Fagen, “I.G.Y.

Can't decide? Hanging from tenterhooks of tentativity? Is your cat both alive and dead? Well, fret no more. Decide uses (pseudo)random data from a variety of sources to make those vexing decisions for you, either in an up-or-down binary fashion, or along the fuzzier spectrum of the Magic 8-Ball.

Decide is run from the command line. Here is sample output:

    $ decide
    Yes

    $ decidebin
    0

    $ eightball
    Most likely
    
    $ dice 2d6
    [ 2 4 ]
    6

Downloading and Installation

Decide may be downloaded from the following link:

decide-1.0.tar.gz: Gzipped TAR archive (12 Kb)

Included in the archive are the Perl program decide.pl and the manual page for the program extracted from the documentation embedded within it, as well as this document. The Perl program is usually called using one of the symbolic links: decide, decidebin, dice, or eightball, which choose the output format. You can use these files in the directory in which you extracted them or install them in your system's library directories to make them available to all users.

This program requires the Perl module LWP::Simple. If your Perl installation lacks this module, you will have to install it (either system-wide or for your own user account) before you can use Decide.

Manual Page

NAME

decide, decidebin, dice, eightball - A just machine, to make big decisions

SYNOPSIS

decide|decidebin|dice|eightball [--apikey key] [--binary] [--decide] [--dice [expr]] [--eightball|8] [--face] [--help] [--hotbits] [--quiet] [--rand] [--urandom] [--verbose] dice_expr

DESCRIPTION

decide, decidebin, dice, and eightball, all aliases of the Perl program decide.pl, make decisions for users, using random or pseudorandom numbers from a variety of sources.

decide and decidebin make yes or no decisions. decide responds "Yes" or "No" on standard output, while decidebin answers with "1" or "0".

eightball responds with one of the twenty answers with which the Magic 8-Ball toy replies to queries.

dice rolls dice using the notation from role-playing and war games and shows the result of the roll.

Random data can be obtained from the Fourmilab HotBits radioactive random number generator in either pseudorandom or genuine random mode, from the system's /dev/urandom generator (if available), or from Perl's built-in rand() function. Options allow selecting which generator is used.

OPTIONS

All options may be abbreviated to their shortest unambiguous prefix. Single-letter mode abbreviations may be aggregated after a single dash.

--apikey key

When querying the HotBits random number generator, the specified key is used as the API Key. The HotBits generator requires an API Key when requesting radioactively-generated random data. If no API Key is specified or key is Pseudorandom, HotBits will return pseudorandom data generated by a high quality algorithm seeded with radioactively-generated data.

--binary

Binary mode output ("1" or "0") is printed on standard output.

--decide

"Yes" or "No" is printed on standard output.

--dice expr

Roll dice to evaluate expr in dice notation, print rolls and result on standard output.

--eightball or --8

One of the twenty Magic 8-Ball responses is printed on standard output.

--face

Show rolls of six-sided dice as Unicode die faces.

--help

Display how to call information.

--hotbits

The HotBits generator is selected. If you require radioactively-generated random data, you must specify a valid HotBits API Key with the --apikey option, otherwise pseudorandom data will be used.

--quiet

No output is printed. The exit status will be set to reflect the result: 1 or 0 for --decide or --decidebin, 0 to 19 for --eightball, and the result of evaluating the dice expression for --dice.

--rand

Perl's built-in rand() generator is used. The quality of this generator depends upon the C language implementation upon which Perl is built; it may be quite poor.

--urandom

The system's /dev/urandom generator will be used, if available. This is usually a high-quality pseudorandom generator seeded with hardware-generated entropy.

--verbose

Debugging information is printed on standard error.

GENERATOR SELECTION

If none of the --hotbits, --urandom, or --rand options are specified, those generators will be tried, in that order, and the first to successfully return a value will be used. The --rand generator will always succeed, and is used if other options fail. The --verbose option will show you which generator was used and what it returned.

DICE EXPRESSIONS

When called as dice or with the --dice option, an expression in dice notation is evaluated, obtaining the result of the dice rolls from the selected generator. Dice notation, commonly used in role-playing and war games, expresses rolls of dice of various kinds and ways of combining them. Rolling A X-sided dice is written as AdX (the "d" may be upper or lower case). For example, the roll of two six-sided dice is written as "2d6", and the result is the sum of the top faces of the two dice, 2 to 12. If A is omitted, 1 is assumed, and if X is omitted, 6 is assumed. When multiple dice are rolled, two lines of output are printed: the first shows the results for the individual dice (identified by the number of faces if different kinds of dice are involved in the roll), while the second shows their sum. For example:

    $ dice 3d6+d8
    d6[ 2 3 6 ] d8[ 2 ]
    13

Dice can have any number of faces from 2 (flipping a coin) to 256, with faces numbered from 1 to the number of faces. All dice are fair: all faces have an equal probability of coming up. You can abbreviate a 100-faced die, often used to compute percentages in games, as "d%".

Multiple sets of rolls can be combined with arithmetic operators into expressions. For example, 3d8-2 means roll three 8-sided dice, sum their values, then subtract two, and 2d6+1d12 returns the sum of rolling two 6-sided and one 12-sided dice. Values can be combined with any of the standard arithmetic operators: +, -, *, and /. You can write multiplication as x or the ISO/Unicode times character, and division as the ISO/Unicode divide character. Parentheses may be used to group complex expressions, for example ((2d6-2)+d4)*3. Expressions which use characters to which the shell is sensitive, such as parentheses and *, must be quoted on the command line.

Rolls can select from the highest or lowest values in a set of dice. Specifying 5d6h3 rolls 5 six-sided dice and returns the sum of the three highest values among the five. Similarly, 5d6l3 sums the three lowest values. If the number is omitted after the h or l, 1 is assumed: 3dh rolls three six-sided dice (the 6 is assumed as no number if given after the d) and chooses the highest value rolled. You can also specify selection in terms of dropping values. (Why? Because gamers think in odd ways.) A specification of 4d8-l2 means roll four 8-sided dice, drop the lowest two values, and sum the remaining two; use -h to drop the highest values. Again, 1 is assumed if no number to drop is given.

FILES

Output is written on standard output unless the --quiet option is specified. Debugging output from the --verbose option is written on standard error.

BUGS

Unless the --verbose option is set, there is no indication if the HotBits or /dev/urandom generators fail and the program falls back to Perl's rand() generator.

In order to use the HotBits random source, the LWP::Simple module must be installed.

In order to use the --urandom source, the operating system must implement the /dev/urandom pseudo device file. Non-Unix-like systems may not provide this facility.

Please report bugs to bugs@fourmilab.ch.

AUTHOR

John Walker (http://www.fourmilab.ch/)

SEE ALSO

    LWP::Simple
    /dev/urandom
    rand()
    http://www.fourmilab.ch/hotbits/
    http://www.perl.org/

VERSION

This is decide version 1.0, released on July 6th, 2017. The current version of this program is always posted at:

http://www.fourmilab.ch/webtools/decide/


This software is in the public domain. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions. This software is provided “as is” without express or implied warranty.

Fourmilab Home Page