random: Do math as unsigned

Hahah bits go brrrr
This commit is contained in:
Fabian Boehm 2023-02-20 19:09:00 +01:00
parent 77a474ee37
commit 0902e29f49

View file

@ -165,10 +165,7 @@ pub fn random(
};
// Safe because end was a valid i64 and the result here is in the range start..=end.
let result: i64 = start
.checked_add_unsigned(rand * step)
.and_then(|x| x.try_into().ok())
.unwrap();
let result: i64 = (start as u64 + (rand * step) as u64) as i64;
streams.out.append(sprintf!(L!("%d\n"), result));
return STATUS_CMD_OK;