diff --git a/Cargo.lock b/Cargo.lock index 21c7063..37dd660 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,7 +83,7 @@ dependencies = [ "phf_codegen", "pretty_assertions", "procfs", - "rand", + "rand 0.9.0", "regex", "rlimit", "tempfile", @@ -180,17 +180,6 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" -[[package]] -name = "getrandom" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - [[package]] name = "getrandom" version = "0.3.1" @@ -199,7 +188,7 @@ checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8" dependencies = [ "cfg-if", "libc", - "wasi 0.13.3+wasi-0.2.2", + "wasi", "windows-targets 0.52.6", ] @@ -321,7 +310,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ "phf_shared", - "rand", + "rand 0.8.5", ] [[package]] @@ -395,19 +384,28 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ - "libc", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ "rand_chacha", - "rand_core", + "rand_core 0.9.2", + "zerocopy", ] [[package]] name = "rand_chacha" -version = "0.3.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.2", ] [[package]] @@ -415,8 +413,15 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "rand_core" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a509b1a2ffbe92afab0e55c8fd99dea1c280e8171bd2d88682bb20bc41cbc2c" dependencies = [ - "getrandom 0.2.12", + "getrandom", + "zerocopy", ] [[package]] @@ -508,6 +513,17 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +[[package]] +name = "syn" +version = "2.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36147f1a48ae0ec2b5b3bc5b537d267457555a10dc06f3dbc8cb11ba3006d3b1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "tempfile" version = "3.17.1" @@ -516,7 +532,7 @@ checksum = "22e5a0acb1f3f55f65cc4a866c361b2fb2a0ff6366785ae6fbb5f85df07ba230" dependencies = [ "cfg-if", "fastrand", - "getrandom 0.3.1", + "getrandom", "once_cell", "rustix 0.38.40", "windows-sys 0.59.0", @@ -622,12 +638,6 @@ version = "0.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cf4c8b31abfb5dc79940d6ca8000a1a6aa42f38711cdeaacb95850c69924cbc" -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wasi" version = "0.13.3+wasi-0.2.2" @@ -819,3 +829,23 @@ name = "yansi" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" + +[[package]] +name = "zerocopy" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde3bb8c68a8f3f1ed4ac9221aad6b10cece3e60a8e2ea54a6a2dec806d0084c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eea57037071898bf96a6da35fd626f4f27e9cee3ead2a6c703cf09d472b2e700" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 9fdba15..8f4e599 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,38 +30,38 @@ feat_common_core = [ ] [workspace.dependencies] -uucore = "0.0.29" clap = { version = "4.4", features = ["wrap_help", "cargo"] } clap_complete = "4.4" clap_mangen = "0.2.20" -regex = "1.10.4" -sysinfo = "0.33.0" libc = "0.2.154" phf = "0.11.2" phf_codegen = "0.11.2" +rand = { version = "0.9.0", features = ["small_rng"] } +regex = "1.10.4" +sysinfo = "0.33.0" +tempfile = "3.9.0" textwrap = { version = "0.16.1", features = ["terminal_size"] } +uucore = "0.0.29" xattr = "1.3.1" -tempfile = "3.9.0" -rand = { version = "0.8.5", features = ["small_rng"] } [dependencies] clap = { workspace = true } clap_complete = { workspace = true } clap_mangen = { workspace = true } -uucore = { workspace = true } phf = { workspace = true } textwrap = { workspace = true } +uucore = { workspace = true } # renice = { optional = true, version = "0.0.1", package = "uu_renice", path = "src/uu/renice" } [dev-dependencies] +libc = { workspace = true } pretty_assertions = "1.4.0" +rand = { workspace = true } regex = { workspace = true } tempfile = { workspace = true } -libc = { workspace = true } -rand = { workspace = true } uucore = { workspace = true, features = ["entries", "process", "signals"] } [target.'cfg(unix)'.dev-dependencies] diff --git a/tests/common/random.rs b/tests/common/random.rs index 42b6eaa..be1df79 100644 --- a/tests/common/random.rs +++ b/tests/common/random.rs @@ -1,10 +1,10 @@ -// This file is part of the uutils coreutils package. +// This file is part of the uutils bsdutils package. // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -use rand::distributions::{Distribution, Uniform}; -use rand::{thread_rng, Rng}; +use rand::distr::{Distribution, Uniform}; +use rand::{rng, Rng}; /// Samples alphanumeric characters `[A-Za-z0-9]` including newline `\n` /// @@ -38,7 +38,7 @@ impl AlphanumericNewline { where R: Rng + ?Sized, { - let idx = rng.gen_range(0..Self::CHARSET.len()); + let idx = rng.random_range(0..Self::CHARSET.len()); Self::CHARSET[idx] } } @@ -80,7 +80,7 @@ impl RandomString { where D: Distribution, { - thread_rng() + rng() .sample_iter(dist) .take(length) .map(|b| b as char) @@ -132,15 +132,15 @@ impl RandomString { return if num_delimiter > 0 { String::from(delimiter as char) } else { - String::from(thread_rng().sample(&dist) as char) + String::from(rng().sample(&dist) as char) }; } let samples = length - 1; - let mut result: Vec = thread_rng().sample_iter(&dist).take(samples).collect(); + let mut result: Vec = rng().sample_iter(&dist).take(samples).collect(); if num_delimiter == 0 { - result.push(thread_rng().sample(&dist)); + result.push(rng().sample(&dist)); return String::from_utf8(result).unwrap(); } @@ -150,9 +150,10 @@ impl RandomString { num_delimiter }; - let between = Uniform::new(0, samples); + // safe to unwrap because samples is at least 1, thus high > low + let between = Uniform::new(0, samples).unwrap(); for _ in 0..num_delimiter { - let mut pos = between.sample(&mut thread_rng()); + let mut pos = between.sample(&mut rng()); let turn = pos; while result[pos] == delimiter { pos += 1; @@ -169,7 +170,7 @@ impl RandomString { if end_with_delimiter { result.push(delimiter); } else { - result.push(thread_rng().sample(&dist)); + result.push(rng().sample(&dist)); } String::from_utf8(result).unwrap() @@ -179,7 +180,7 @@ impl RandomString { #[cfg(test)] mod tests { use super::*; - use rand::distributions::Alphanumeric; + use rand::distr::Alphanumeric; #[test] fn test_random_string_generate() {