Update rand crate to 0.9.2

Function names containing `gen` have been deprecated to avoid conflicts
with the Rust 2024 keyword, so this commit also switches to the new
names.

Part of #12030
This commit is contained in:
Daniel Rainer
2025-11-22 22:24:32 +01:00
committed by danielrainer
parent b1769658f5
commit c9ab2c26aa
6 changed files with 30 additions and 14 deletions

21
Cargo.lock generated
View File

@@ -175,7 +175,7 @@ dependencies = [
"phf 0.12.1",
"phf_codegen 0.12.1",
"portable-atomic",
"rand",
"rand 0.9.2",
"rsconf",
"rust-embed",
"serial_test",
@@ -523,7 +523,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c80231409c20246a13fddb31776fb942c38553c51e871f8cbd687a4cfb5843d"
dependencies = [
"phf_shared 0.11.3",
"rand",
"rand 0.8.5",
]
[[package]]
@@ -596,7 +596,16 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"rand_core",
"rand_core 0.6.4",
]
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_core 0.9.3",
]
[[package]]
@@ -605,6 +614,12 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
[[package]]
name = "redox_syscall"
version = "0.5.18"

View File

@@ -44,7 +44,7 @@ portable-atomic = { version = "1", default-features = false, features = [
"fallback",
] }
proc-macro2 = "1.0"
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
rand = { version = "0.9.2", default-features = false, features = ["small_rng"] }
rsconf = "0.2.2"
rust-embed = { version = "8.7.2", features = [
"deterministic-timestamps",

View File

@@ -62,7 +62,7 @@ pub fn random(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> B
return Err(STATUS_INVALID_ARGS);
}
let rand = RNG.lock().unwrap().gen_range(0..arg_count - 1);
let rand = RNG.lock().unwrap().random_range(0..arg_count - 1);
streams.out.appendln(argv[i + 1 + rand]);
return Ok(SUCCESS);
}
@@ -156,7 +156,7 @@ fn parse_ull(streams: &mut IoStreams, cmd: &wstr, num: &wstr) -> Result<u64, wut
let rand = {
let mut engine = RNG.lock().unwrap();
engine.gen_range(0..=possibilities)
engine.random_range(0..=possibilities)
};
// Safe because end was a valid i64 and the result here is in the range start..=end.

View File

@@ -2116,7 +2116,7 @@ fn escape_test(escape_style: EscapeStringStyle, unescape_style: UnescapeStringSt
let mut escaped_string;
for _ in 0..(ESCAPE_TEST_COUNT as u32) {
random_string.clear();
let length = rng.gen_range(0..=(2 * ESCAPE_TEST_LENGTH));
let length = rng.random_range(0..=(2 * ESCAPE_TEST_LENGTH));
for _ in 0..length {
random_string
.push(char::from_u32((rng.next_u32() % ESCAPE_TEST_CHAR as u32) + 1).unwrap());
@@ -2192,7 +2192,7 @@ fn test_convert() {
let mut origin = Vec::new();
for _ in 0..ESCAPE_TEST_COUNT {
let length: usize = rng.gen_range(0..=(2 * ESCAPE_TEST_LENGTH));
let length: usize = rng.random_range(0..=(2 * ESCAPE_TEST_LENGTH));
origin.resize(length, 0);
rng.fill_bytes(&mut origin);

View File

@@ -731,7 +731,7 @@ fn save_unless_disabled(&mut self) {
// the counter.
let countdown_to_vacuum = self
.countdown_to_vacuum
.get_or_insert_with(|| get_rng().gen_range(0..VACUUM_FREQUENCY));
.get_or_insert_with(|| get_rng().random_range(0..VACUUM_FREQUENCY));
// Determine if we're going to vacuum.
let mut vacuum = false;
@@ -1808,10 +1808,11 @@ fn history_contains(history: &History, txt: &wstr) -> bool {
fn random_string(rng: &mut SmallRng) -> WString {
let mut result = WString::new();
let max = rng.gen_range(1..=32);
let max = rng.random_range(1..=32);
for _ in 0..max {
let c = char::from_u32(u32::try_from(1 + rng.gen_range(0..ESCAPE_TEST_CHAR)).unwrap())
.unwrap();
let c =
char::from_u32(u32::try_from(1 + rng.random_range(0..ESCAPE_TEST_CHAR)).unwrap())
.unwrap();
result.push(c);
}
result
@@ -1938,7 +1939,7 @@ macro_rules! test_history_matches {
}
// Generate some paths.
let paths: PathList = (0..rng.gen_range(0..6))
let paths: PathList = (0..rng.random_range(0..6))
.map(|_| random_string(&mut rng))
.collect();

View File

@@ -674,7 +674,7 @@ fn test_wwrite_to_fd() {
assert!(fd.is_valid());
let mut input = WString::new();
for _i in 0..size {
input.push(rng.r#gen());
input.push(rng.random());
}
let amt = wwrite_to_fd(&input, fd.fd()).unwrap();