From fe21c4b7fd6c2b644569cb4b53e150ebd9c64044 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Sun, 14 Oct 2018 11:33:44 +0200 Subject: [PATCH] Update to Rand 0.5 (#1288) * factor: Update to Rand 0.5 * shuf: Update to Rand 0.5 * shred: Update to Rand 0.5 * mktemp: Update to Rand 0.5 --- Cargo.lock | 42 +++++++++++++++++++++++++++++++++++------- src/factor/Cargo.toml | 2 +- src/factor/factor.rs | 20 +++++++++++--------- src/mktemp/Cargo.toml | 2 +- src/mktemp/mktemp.rs | 2 +- src/mktemp/tempdir.rs | 3 ++- src/shred/Cargo.toml | 2 +- src/shred/shred.rs | 2 +- src/shuf/Cargo.toml | 2 +- src/shuf/shuf.rs | 4 ++-- 10 files changed, 56 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ac2fcaea..27e0be778 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,6 +265,14 @@ dependencies = [ "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cmake" version = "0.1.29" @@ -492,7 +500,7 @@ dependencies = [ name = "factor" version = "0.0.1" dependencies = [ - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.1", ] @@ -603,7 +611,7 @@ dependencies = [ [[package]] name = "half" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -850,7 +858,7 @@ name = "mktemp" version = "0.0.1" dependencies = [ "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.1", ] @@ -977,7 +985,7 @@ version = "0.0.1" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "half 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "half 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.1", ] @@ -1163,6 +1171,23 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +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.42 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "readlink" version = "0.0.1" @@ -1379,7 +1404,7 @@ dependencies = [ "filetime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.1", ] @@ -1389,7 +1414,7 @@ name = "shuf" version = "0.0.1" dependencies = [ "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "uucore 0.0.1", ] @@ -2052,6 +2077,7 @@ dependencies = [ "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum clippy 0.0.212 (registry+https://github.com/rust-lang/crates.io-index)" = "7e253af13a0cc39c7f22cf16f1be49d593dedc5895fe2fbb15f14d66ead00533" "checksum clippy_lints 0.0.212 (registry+https://github.com/rust-lang/crates.io-index)" = "bd2326065405649672adbd5cb30dad2fad3a470935653d51c70591d47d3a8512" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb" "checksum cpp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d1cd8699ffa1b18fd388183f7762e0545eddbd5c6ec95e9e3b42a4a71a507ff" "checksum cpp_build 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c47531e7e09532ad4827098729794f5e1a5b1c2ccbb5e295498d2e7ab451c445" @@ -2076,7 +2102,7 @@ dependencies = [ "checksum generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fceb69994e330afed50c93524be68c42fa898c2d9fd4ee8da03bd7363acd26f2" "checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" -"checksum half 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e66d1b6cf4ea677bbae5f3d086ac8a9f70b1ff0c1b0d920b1610965375c33e0" +"checksum half 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee6c0438de3ca4d8cac2eec62b228e2f8865cfe9ebefea720406774223fa2d2e" "checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" "checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum if_chain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "61bb90bdd39e3af69b0172dfc6130f6cd6332bf040fbb9bdd4401d37adbd48b8" @@ -2112,6 +2138,8 @@ dependencies = [ "checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" +"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13c93d55961981ba9226a213b385216f83ab43bd6ac53ab16b2eeb47e337cf4e" diff --git a/src/factor/Cargo.toml b/src/factor/Cargo.toml index b5d5fd4d4..97d987b4f 100644 --- a/src/factor/Cargo.toml +++ b/src/factor/Cargo.toml @@ -8,7 +8,7 @@ name = "uu_factor" path = "factor.rs" [dependencies] -rand = "0.4.2" +rand = "0.5" uucore = { path="../uucore" } [[bin]] diff --git a/src/factor/factor.rs b/src/factor/factor.rs index e505e077d..97b92a4d3 100644 --- a/src/factor/factor.rs +++ b/src/factor/factor.rs @@ -19,7 +19,9 @@ extern crate rand; extern crate uucore; use numeric::*; -use rand::distributions::{IndependentSample, Range}; +use rand::distributions::{Distribution, Uniform}; +use rand::{SeedableRng, thread_rng}; +use rand::rngs::SmallRng; use std::cmp::{max, min}; use std::io::{stdin, BufRead, BufReader}; use std::num::Wrapping; @@ -51,12 +53,12 @@ fn gcd(mut a: u64, mut b: u64) -> u64 { } fn rho_pollard_find_divisor(num: u64) -> u64 { - let range = Range::new(1, num); - let mut rng = rand::weak_rng(); - let mut x = range.ind_sample(&mut rng); + let range = Uniform::new(1, num); + let mut rng = SmallRng::from_rng(&mut thread_rng()).unwrap(); + let mut x = range.sample(&mut rng); let mut y = x; - let mut a = range.ind_sample(&mut rng); - let mut b = range.ind_sample(&mut rng); + let mut a = range.sample(&mut rng); + let mut b = range.sample(&mut rng); loop { x = rho_pollard_pseudorandom_function(x, a, b, num); @@ -65,10 +67,10 @@ fn rho_pollard_find_divisor(num: u64) -> u64 { let d = gcd(num, max(x, y) - min(x, y)); if d == num { // Failure, retry with different function - x = range.ind_sample(&mut rng); + x = range.sample(&mut rng); y = x; - a = range.ind_sample(&mut rng); - b = range.ind_sample(&mut rng); + a = range.sample(&mut rng); + b = range.sample(&mut rng); } else if d > 1 { return d; } diff --git a/src/mktemp/Cargo.toml b/src/mktemp/Cargo.toml index e456cce60..8a2226793 100644 --- a/src/mktemp/Cargo.toml +++ b/src/mktemp/Cargo.toml @@ -11,7 +11,7 @@ path = "mktemp.rs" [dependencies] uucore = { path="../uucore" } getopts = "0.2.18" -rand = "0.4" +rand = "0.5" tempfile = "2.1.5" [[bin]] diff --git a/src/mktemp/mktemp.rs b/src/mktemp/mktemp.rs index 97e8a3a90..7c65d3e41 100644 --- a/src/mktemp/mktemp.rs +++ b/src/mktemp/mktemp.rs @@ -176,7 +176,7 @@ pub fn dry_exec(mut tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str) -> unsafe { // We guarantee utf8. let bytes = &mut buf.as_mut_vec()[prefix.len()..prefix.len() + rand]; - rand::thread_rng().fill_bytes(bytes); + rand::thread_rng().fill(bytes); for byte in bytes.iter_mut() { *byte = match *byte % 62 { v @ 0...9 => (v + '0' as u8), diff --git a/src/mktemp/tempdir.rs b/src/mktemp/tempdir.rs index 0dfc2d51b..b3f2e60e1 100644 --- a/src/mktemp/tempdir.rs +++ b/src/mktemp/tempdir.rs @@ -2,6 +2,7 @@ extern crate rand; use rand::{thread_rng, Rng}; +use rand::distributions::Alphanumeric; use std::io::Result as IOResult; use std::io::{Error, ErrorKind}; @@ -32,7 +33,7 @@ pub fn new_in>( ) -> IOResult { let mut rng = thread_rng(); for _ in 0..NUM_RETRIES { - let rand_chars: String = rng.gen_ascii_chars().take(rand).collect(); + let rand_chars: String = rng.sample_iter(&Alphanumeric).take(rand).collect(); let leaf = format!("{}{}{}", prefix, rand_chars, suffix); let path = tmpdir.as_ref().join(&leaf); match create_dir(&path) { diff --git a/src/shred/Cargo.toml b/src/shred/Cargo.toml index 15f09de2f..b73538b91 100644 --- a/src/shred/Cargo.toml +++ b/src/shred/Cargo.toml @@ -9,7 +9,7 @@ name = "uu_shred" path = "shred.rs" [dependencies] -rand = "0.4" +rand = "0.5" filetime = "0.2.1" getopts = "0.2.18" libc = "0.2.42" diff --git a/src/shred/shred.rs b/src/shred/shred.rs index ec4f99ff9..a2852bc86 100644 --- a/src/shred/shred.rs +++ b/src/shred/shred.rs @@ -180,7 +180,7 @@ impl<'a> Iterator for BytesGenerator<'a> { bytes.set_len(this_block_size); } let mut rng = self.rng.as_ref().unwrap().borrow_mut(); - rng.fill_bytes(&mut bytes[..]); + rng.fill(&mut bytes[..]); } PassType::Pattern(pattern) => { let skip = { diff --git a/src/shuf/Cargo.toml b/src/shuf/Cargo.toml index 8efeef66e..5caca95bd 100644 --- a/src/shuf/Cargo.toml +++ b/src/shuf/Cargo.toml @@ -10,7 +10,7 @@ path = "shuf.rs" [dependencies] getopts = "0.2.18" -rand = "0.4.2" +rand = "0.5" uucore = { path="../uucore" } [[bin]] diff --git a/src/shuf/shuf.rs b/src/shuf/shuf.rs index 0d057f892..6f5e0ee28 100644 --- a/src/shuf/shuf.rs +++ b/src/shuf/shuf.rs @@ -283,8 +283,8 @@ enum WrappedRng { impl WrappedRng { fn next_usize(&mut self) -> usize { match *self { - WrappedRng::RngFile(ref mut r) => r.next_u32() as usize, - WrappedRng::RngDefault(ref mut r) => r.next_u32() as usize, + WrappedRng::RngFile(ref mut r) => r.gen(), + WrappedRng::RngDefault(ref mut r) => r.gen(), } } }