From 8e094de6aae887abf2530cdefd802fbfd2f138b1 Mon Sep 17 00:00:00 2001 From: alpaylan Date: Sat, 14 Dec 2024 14:57:32 -0500 Subject: [PATCH] fix random character generation --- simulator/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/simulator/main.rs b/simulator/main.rs index 8a7f10d24..30d3a0176 100644 --- a/simulator/main.rs +++ b/simulator/main.rs @@ -170,14 +170,14 @@ impl ArbitraryFrom for LTValue { t.pop(); LTValue(Value::Text(t)) } else { - let index = rng.gen_range(0..t.len()); let mut t = t.chars().map(|c| c as u32).collect::>(); + let index = rng.gen_range(0..t.len()); t[index] -= 1; // Mutate the rest of the string for i in (index + 1)..t.len() { - t[i] = rng.gen_range(0..=255); + t[i] = rng.gen_range('a' as u32..='z' as u32); } - let t = t.into_iter().map(|c| c as u8 as char).collect::(); + let t = t.into_iter().map(|c| char::from_u32(c).unwrap_or('z')).collect::(); LTValue(Value::Text(t)) } } @@ -227,14 +227,14 @@ impl ArbitraryFrom for GTValue { t.push(rng.gen_range(0..=255) as u8 as char); GTValue(Value::Text(t)) } else { - let index = rng.gen_range(0..t.len()); let mut t = t.chars().map(|c| c as u32).collect::>(); + let index = rng.gen_range(0..t.len()); t[index] += 1; // Mutate the rest of the string for i in (index + 1)..t.len() { - t[i] = rng.gen_range(0..=255); + t[i] = rng.gen_range('a' as u32..='z' as u32); } - let t = t.into_iter().map(|c| c as u8 as char).collect::(); + let t = t.into_iter().map(|c| char::from_u32(c).unwrap_or('a')).collect::(); GTValue(Value::Text(t)) } }