Adds --buel and --bule options. Updates dependencies and documentation.

This commit is contained in:
Joe Ardent 2020-02-02 17:21:45 -08:00
parent c67c1c459c
commit 7892dffc46
6 changed files with 200 additions and 132 deletions

195
Cargo.lock generated
View file

@ -1,184 +1,193 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi",
]
[[package]]
name = "atty"
version = "0.2.11"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "bitflags"
version = "1.0.4"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "c2-chacha"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
dependencies = [
"ppv-lite86",
]
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "clap"
version = "2.32.0"
version = "2.33.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
dependencies = [
"ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "fuchsia-zircon"
version = "0.3.3"
name = "hermit-abi"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc",
]
[[package]]
name = "fuchsia-zircon-sys"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.43"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
[[package]]
name = "ppv-lite86"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
[[package]]
name = "rand"
version = "0.5.5"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
"cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"getrandom",
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a2a90da8c7523f554344f921aa97283eadf6ac484a6d2a7d0212fa7f8d6853"
dependencies = [
"c2-chacha",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.2.2"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
"rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"getrandom",
]
[[package]]
name = "rand_core"
version = "0.3.0"
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
"rand_core",
]
[[package]]
name = "randical"
version = "0.1.1"
version = "1.6.1"
dependencies = [
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_termios"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"clap",
"rand",
]
[[package]]
name = "strsim"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "termion"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "textwrap"
version = "0.10.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width",
]
[[package]]
name = "unicode-width"
version = "0.1.5"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
[[package]]
name = "vec_map"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
[[package]]
name = "winapi"
version = "0.3.6"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d"
"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
"checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372"
"checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db"
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -1,7 +1,8 @@
[package]
name = "randical"
version = "0.1.1"
version = "1.6.1"
authors = ["Joe Ardent <code@ardent.nebcorp.com>"]
edition = "2018"
description = "A simple UNIX commandline utility to generate sequences of random values of different types."
@ -18,5 +19,5 @@ license = "GPL-3.0-or-later"
maintenance = { status = "actively-developed" }
[dependencies]
rand = "~0.5.5"
clap = "~2.32.0"
rand = "0.7"
clap = "2"

View file

@ -1,32 +1,50 @@
# Radical Random Value Generator
```randical``` is a simple unix commandline utility to generate a series of
random values of varying types. See below for usage and examples.
random values of varying types, with uniform distribution. See below for usage and examples.
```text
Radical Random Value Generator 1.61
Generates arbitrary numbers of uniformly distributed random values.
USAGE:
randical [FLAGS] [OPTIONS]
FLAGS:
-e, --exit Randomly exit with either status 0, like /bin/true, or status 1, like /bin/false. Technically
compatible with all other options, but doing so could obscure potential errors. Sets default number
of values to print out to 0.
--buel Prints either 'Here.' or 'Um, he's sick. My best friend's sister's boyfriend's brother's girlfriend
heard from this guy who knows this kid who's going with the girl who saw Ferris pass out at 31
Flavors last night. I guess it's pretty serious.', with equal probability. Not compatible with `-t`
or `--bule`.
--bule Prints either 'true' or 'false', with equal probability. Not compatible with `-t` or `--buel`.
-e, --exit With equal probability, exit with either status 0, like /bin/true, or status 1, like /bin/false.
Technically compatible with all other options, but exit status will have no relation to any
generated output. Sets default number of values to print to 0.
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-n, --num-vals <NUM_VALS> Number of random values to print out. Defaults to 1.
-t, --type <TYPE> Type of random value to print. Defaults to 'bool', with true represented as '1', and
false as '0'.
Possible values accepted are 'b'ool, 'f'loat64, 'u'nsigned64, and 's'igned64
-t, --type <TYPE> Type of random value to print. Defaults to 'bool', with true represented as 'Radical!',
and false as 'Bogus.'.
Possible values are 'b'ool, 'f'loat64, 'u'nsigned64, and 's'igned64
```
Some examples:
``` text
$ randical -n 10 # print out ten bools
Bogus.
Radical!
Radical!
Bogus.
Radical!
Bogus.
Radical!
Bogus.
Radical!
Radical!
$ randical -t u -n 10 # print out ten 64-bit unsigned integers
5787939472744910229
3687549088276320089
@ -38,6 +56,7 @@ $ randical -t u -n 10 # print out ten 64-bit unsigned integers
16771457972349018485
7609614558571403402
8284410620633392032
$ randical -n 10 -t s # print out ten 64-bit signed integers
-3655402238002064604
7349054970592683859
@ -49,6 +68,7 @@ $ randical -n 10 -t s # print out ten 64-bit signed integers
-4580256882393100929
3009966650832330749
6676004827997477043
$ randical -n 10 -t f # print out ten 64-bit floating-point numbers in [0,1)
0.603028217883161
0.004087838255832366
@ -60,23 +80,11 @@ $ randical -n 10 -t f # print out ten 64-bit floating-point numbers in [0,1)
0.4487145473864015
0.3171660044903156
0.29296569910381276
$ randical -n 10 # print out ten "bools"
0
0
0
1
0
0
1
1
1
0
$ randical -n 1 -t f -e # print out one float and exit with a status randomly true or false, in the unix exit status sense.
0.9543066009689831
$ randical -e # exit with status 0 or 1, with equal probability
$ echo $?
1
$ randical -n 1 -t f -e
0.6178924136785371
$ randical -e
$ echo $?
0
$

View file

@ -1 +1 @@
1
1.61

View file

@ -24,4 +24,9 @@ Cool.
## What version is randical now?
See the ```VERSION``` file.
Canonically, see the ```VERSION``` file. Heretically, now that there have been
at least three releases, the version string in the ```Cargo.toml``` file will
always be of the form "1.6.x", where *x* is at least one digit long, starting
with "1". Each subsequent release will append the next digit of *phi* to
*x*. The number of releases can be calculated by counting the number of digits
in *x* and adding 2 to that.

View file

@ -1,18 +1,23 @@
extern crate clap;
extern crate rand;
use std::process::exit;
use clap::{App, Arg, ArgMatches};
use rand::prelude::*;
const VERSION: &str = "1";
const VERSION: &str = "1.61";
const DEFAULT_NUM_VALS: usize = 1;
const BUEL_TRUE: &str = "Here.";
const BUEL_FALSE: &str = "Um, he's sick. My best friend's sister's boyfriend's brother's girlfriend heard from this guy who knows this kid who's going with the girl who saw Ferris pass out at 31 Flavors last night. I guess it's pretty serious.";
const BULE_TRUE: &str = "true";
const BULE_FALSE: &str = "false";
fn get_args() -> ArgMatches<'static> {
App::new("Radical Random Value Generator")
.version(VERSION)
.about("Generates arbitrary numbers of uniformly distributed random values.")
.arg(
Arg::with_name("NUM_VALS")
.short("n")
@ -28,31 +33,71 @@ fn get_args() -> ArgMatches<'static> {
.short("t")
.long("type")
.takes_value(true)
.help("Type of random value to print. Defaults to 'bool', with true represented as '1', and false as '0'.\nPossible values accepted are 'b'ool, 'f'loat64, 'u'nsigned64, and 's'igned64"),
.help("Type of random value to print. Defaults to 'bool'.\nPossible values are 'b'ool, 'f'loat64, 'u'nsigned64, and 's'igned64"),
)
.arg(
Arg::with_name("BULE")
.long("bule")
.takes_value(false)
.conflicts_with("TYPE")
.conflicts_with("BUEL")
.help(&format!("Prints either '{}' or '{}', with equal probability. Not compatible with `-t` or `--buel`.",
BULE_TRUE, BULE_FALSE))
)
.arg(
Arg::with_name("BUEL")
.long("buel")
.takes_value(false)
.conflicts_with("TYPE")
.conflicts_with("BULE")
.help(&format!("Prints either '{}' or '{}', with equal probability. Not compatible with `-t` or `--bule`.",
BUEL_TRUE, BUEL_FALSE))
)
.arg(
Arg::with_name("EXIT")
.short("e")
.long("exit")
.takes_value(false)
.help("Randomly exit with either status 0, like /bin/true, or status 1, like /bin/false. Technically compatible with all other options, but doing so could obscure potential errors. Sets default number of values to print out to 0.")
.help("With equal probability, exit with either status 0, like /bin/true, or status 1, like /bin/false. Technically compatible with all other options, but exit status will have no relation to any generated output. Sets default number of values to print to 0.")
)
.get_matches()
}
fn print_bool(b: &mut ThreadRng) {
let t = if b.gen() { 1 } else { 0 };
fn print_bool<'a>(b: &'a mut ThreadRng, args: &'a ArgMatches) {
let t: &str;
match b.gen() {
true => {
if args.is_present("BULE") {
t = BULE_TRUE;
} else if args.is_present("BUEL") {
t = BUEL_TRUE;
} else {
t = "Radical!";
}
}
false => {
if args.is_present("BULE") {
t = BULE_FALSE;
} else if args.is_present("BUEL") {
t = BUEL_FALSE;
} else {
t = "Bogus.";
}
}
}
println!("{}", t);
}
fn get_generator(args: &ArgMatches) -> Box<dyn FnMut() -> ()> {
fn get_generator<'a>(args: &'a ArgMatches) -> Box<(dyn FnMut() + 'a)> {
let mut rng = thread_rng();
match args.value_of("TYPE").unwrap_or("b") {
"f" => Box::new(move || println!("{}", rng.gen::<f64>())),
"u" => Box::new(move || println!("{}", rng.gen::<u64>())),
"s" => Box::new(move || println!("{}", rng.gen::<i64>())),
_ => Box::new(move || print_bool(&mut rng)),
"b" => Box::new(move || print_bool(&mut rng, args)),
_ => panic!(),
}
}