-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
24 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "tinymt" | ||
version = "1.0.7" | ||
version = "1.0.8" | ||
authors = ["Torao Takami <[email protected]>"] | ||
edition = "2021" | ||
repository = "https://github.com/torao/tinymt" | ||
|
@@ -9,6 +9,7 @@ license = "MIT" | |
readme = "README.md" | ||
description = "Rust implementation of TinyMT 64/32 - a lightweight variant of Mersenne Twister PRNG" | ||
documentation = "https://docs.rs/tinymt" | ||
members = ["cli"] | ||
|
||
[badges] | ||
circle-ci = { repository = "torao/tinymt", branch = "master" } | ||
|
@@ -23,4 +24,4 @@ rand = { version = "0.8", default-features = false } | |
rand = { version = "0.8", default-features = false, features = ["getrandom"] } | ||
|
||
[target.'cfg(not(windows))'.dev-dependencies] | ||
pprof = { version = "0.10", features = ["flamegraph"] } | ||
pprof = { version = "0.11", features = ["flamegraph"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
extern crate clap; | ||
extern crate rand; | ||
extern crate tinymt; | ||
|
||
use clap::{App, Arg}; | ||
use clap::{Arg, Command}; | ||
use rand::{Rng, RngCore, SeedableRng}; | ||
use std::process; | ||
use std::str::FromStr; | ||
|
@@ -17,7 +13,7 @@ where | |
} | ||
|
||
/// Generate TinyMT32 with specified seed. | ||
fn rand32(seed: Option<&str>) -> Result<TinyMT32, String> { | ||
fn rand32(seed: Option<&String>) -> Result<TinyMT32, String> { | ||
Ok(if let Some(seed) = seed { | ||
let seed: u32 = num(seed)?; | ||
TinyMT32::from_seed_u32(seed) | ||
|
@@ -27,7 +23,7 @@ fn rand32(seed: Option<&str>) -> Result<TinyMT32, String> { | |
} | ||
|
||
/// Generate TinyMT64 with specified seed. | ||
fn rand64(seed: Option<&str>) -> Result<TinyMT64, String> { | ||
fn rand64(seed: Option<&String>) -> Result<TinyMT64, String> { | ||
Ok(if let Some(seed) = seed { | ||
let seed: u64 = num(seed)?; | ||
TinyMT64::from_seed_u64(seed) | ||
|
@@ -45,9 +41,9 @@ fn main() { | |
|
||
fn exec() -> Result<(), String> { | ||
let args = arguments().get_matches(); | ||
let seed = args.value_of("seed"); | ||
let n: usize = num(args.value_of("count").unwrap())?; | ||
match args.value_of("type").unwrap() { | ||
let seed = args.get_one::<String>("seed"); | ||
let n = num(args.get_one::<String>("count").unwrap())?; | ||
match args.get_one::<String>("type").unwrap().as_str() { | ||
"int" | "int32" | "i32" | "u32" | "32" => { | ||
print(&mut rand32(seed)?, n, |r| format!("{}", r.next_u32())) | ||
} | ||
|
@@ -62,8 +58,8 @@ fn exec() -> Result<(), String> { | |
} | ||
"string" | "str" | "s" => { | ||
let mut r = rand64(seed)?; | ||
let length: usize = num(args.value_of("length").unwrap())?; | ||
let radix: Vec<char> = args.value_of("radix").unwrap().chars().collect(); | ||
let length: usize = num(args.get_one::<String>("length").unwrap())?; | ||
let radix: Vec<char> = args.get_one::<String>("radix").unwrap().chars().collect(); | ||
for _ in 0..n { | ||
println!( | ||
"{}", | ||
|
@@ -87,41 +83,41 @@ fn error(message: String) -> ! { | |
process::exit(1) | ||
} | ||
|
||
fn arguments() -> App<'static> { | ||
App::new("tinymt") | ||
fn arguments() -> Command { | ||
Command::new("tinymt") | ||
.version("1.0") | ||
.author("Torao Takami <[email protected]>") | ||
.about("TinyMT 64/32-bit Random Number Generator CLI") | ||
.arg( | ||
Arg::with_name("count") | ||
Arg::new("count") | ||
.short('n') | ||
.takes_value(true) | ||
.number_of_values(1) | ||
.default_value("1") | ||
.help("number to generate"), | ||
) | ||
.arg( | ||
Arg::with_name("type") | ||
Arg::new("type") | ||
.short('t') | ||
.long("type") | ||
.takes_value(true) | ||
.number_of_values(1) | ||
.default_value("double") | ||
.help("generate random number of int, long, float, double or string type"), | ||
) | ||
.arg( | ||
Arg::with_name("length") | ||
Arg::new("length") | ||
.short('l') | ||
.long("length") | ||
.takes_value(true) | ||
.number_of_values(1) | ||
.default_value("32") | ||
.help("the number of characters when generating random strings"), | ||
) | ||
.arg( | ||
Arg::with_name("radix") | ||
Arg::new("radix") | ||
.short('r') | ||
.long("radix") | ||
.takes_value(true) | ||
.number_of_values(1) | ||
.default_value("0123456789abcdefghijklmnopqrstuvwxyz") | ||
.help("characters to be used when generating random string"), | ||
) | ||
.arg(Arg::with_name("seed").help("seed of pseudo-random number generator")) | ||
.arg(Arg::new("seed").help("seed of pseudo-random number generator")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters