Whenever I try to generate a number less than a certain large prime, the program seems to get caught in a loop. It takes up a bunch of CPU time and I've never waited long enough to see it (possibly) return a value. Here's a small program that will hang:
extern crate ramp;
extern crate rand;
use rand::Rng;
use ramp::int::{Int, RandomInt};
static P_521: &'static str = "\
000001ffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffffffffffff\
ffffffffffffffffffffffffffffffffffffffff";
fn main() {
let big = Int::from_str_radix(P_521, 16).unwrap();
let small = Int::from(957);
let mut rng = rand::thread_rng();
let small_rand = rng.gen_uint_below(&small);
println!("Small random {}", &small_rand);
let big_rand = rng.gen_uint_below(&big); // Hangs here
println!("Big random {}", &big_rand);
}
Whenever I try to generate a number less than a certain large prime, the program seems to get caught in a loop. It takes up a bunch of CPU time and I've never waited long enough to see it (possibly) return a value. Here's a small program that will hang: