Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 57 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 13 additions & 12 deletions tests/common/random.rs
Original file line number Diff line number Diff line change
@@ -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`
///
Expand Down Expand Up @@ -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]
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ impl RandomString {
where
D: Distribution<u8>,
{
thread_rng()
rng()
.sample_iter(dist)
.take(length)
.map(|b| b as char)
Expand Down Expand Up @@ -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<u8> = thread_rng().sample_iter(&dist).take(samples).collect();
let mut result: Vec<u8> = 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();
}

Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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() {
Expand Down