Hello,
I don't understand why t has an unexpected value.
fn main() {
use std::num::Wrapping;
let r = Wrapping(16807);
let s = r * r; // s = 282475249;
let t = r * s; // t = 1622647863; // instead of 1622650073
println!("{} {} {}", r, s, t);
}
But that's my point: the original code doesn't use wrapping. It's also not using 32-bit integers. If you write different code, you're going to get a different answer.
You need to go back and read the reference code more carefully. There's even an explicit note about this:
Note that the multiplication by 16807 is done in a large enough signed integer type so that there is no overflow before the modulo operation.
Note that 2147483647 is different to 2147483648. This is a mod operation, not bitwise and operation. You need to do % 2147483647, you cannot use wrapping, as this isn't a power of 2.