Skip to content

Commit

Permalink
upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
torao committed Mar 15, 2023
1 parent dd8b4f7 commit 06f306d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
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"
Expand All @@ -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" }
Expand All @@ -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"] }
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ maintenance = { status = "passively-maintained" }

[dependencies]
tinymt = { version = "^1.0.0", path = "../" }
clap = "^3.2.21"
clap = "^4.1.8"
rand = "^0.8.5"

[[bin]]
Expand Down
42 changes: 19 additions & 23 deletions cli/src/main.rs
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;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()))
}
Expand All @@ -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!(
"{}",
Expand All @@ -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"))
}
2 changes: 1 addition & 1 deletion src/tinymt64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn period_certification(random: &mut TinyMT64) {
/// @param seed a 64-bit unsigned integer used as a seed.
pub fn tinymt64_init(random: &mut TinyMT64, seed: u64) {
random.status[0] = seed ^ ((random.mat1 as u64) << 32);
random.status[1] = (random.mat2 as u64) ^ (random.tmat as u64);
random.status[1] = (random.mat2 as u64) ^ random.tmat;
for i in 1..MIN_LOOP {
random.status[i & 1] ^= (i as u64).wrapping_add(
6_364_136_223_846_793_005_u64
Expand Down

0 comments on commit 06f306d

Please sign in to comment.