mirror of
https://github.com/uutils/coreutils
synced 2024-12-14 23:32:39 +00:00
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
This commit is contained in:
parent
1b1751d721
commit
fe21c4b7fd
10 changed files with 56 additions and 25 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -8,7 +8,7 @@ name = "uu_factor"
|
|||
path = "factor.rs"
|
||||
|
||||
[dependencies]
|
||||
rand = "0.4.2"
|
||||
rand = "0.5"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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]]
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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<P: AsRef<Path>>(
|
|||
) -> IOResult<String> {
|
||||
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) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -10,7 +10,7 @@ path = "shuf.rs"
|
|||
|
||||
[dependencies]
|
||||
getopts = "0.2.18"
|
||||
rand = "0.4.2"
|
||||
rand = "0.5"
|
||||
uucore = { path="../uucore" }
|
||||
|
||||
[[bin]]
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue