nanorand-rs
nanorand-rs copied to clipboard
Panic on `generate_range`
I'm trying out this lovely library but encountered this panic when calling rng.generate_range<u16>(8192..) on a WyRand RNG:
thread 'protocol::tests::sim_connect_to_peers' panicked at 'attempt to add with overflow', /home/cloudhead/.cargo/registry/src/github.com-1ecc6299db9ec823/nanorand-0.6.1/src/gen.rs:108:1
stack backtrace:
0: rust_begin_unwind
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:50:5
3: <u16 as nanorand::gen::RandomRange<R>>::random_range
at /home/cloudhead/.cargo/registry/src/github.com-1ecc6299db9ec823/nanorand-0.6.1/src/gen.rs:50:21
4: nanorand::rand::Rng::generate_range
at /home/cloudhead/.cargo/registry/src/github.com-1ecc6299db9ec823/nanorand-0.6.1/src/rand/mod.rs:57:3
Any idea why this is happening? I call the RNG in a lot of places and this seems to be the only thing failing.
Debugging ...
The values that cause this issue are:
(m >> BITS) as u16 = 58161
lower = 8192
Is this still happening in 0.7?
From my testing this appears to be fixed on 0.7, or at least I could not recreate it. I couldn't recreate it for 0.6 release either strangely enough (which I assume @cloudhead was on at the time), but I could recreate the error in 0.5.
Alright, this seems to be fixed, then. Thanks for testing!