dimanche 4 octobre 2015

Rust GSL library always returns the same number for a random number generator

I am using the rgsl library in Rust that wraps functions from the C GSL math libraries. I was using a random number generator function, but I am always getting the same exact value whenever I generate a new random number. I imagine that the number should vary upon each run of the function. Is there something that I am missing? Do I need to set a new random seed each time or such?

extern crate rgsl;

use rgsl::Rng;

fn main() {
    rgsl::RngType::env_setup();

    let t = rgsl::rng::default();
    let r = Rng::new(&t).unwrap()

    let val = rgsl::randist::binomial::binomial(&r, 0.01f64, 1u32);
    print!("{}",val);
}

The value I keep getting is 1, which seems really high considering the probability of obtaining a 1 is 0.01.




Aucun commentaire:

Enregistrer un commentaire