genetic

genetic algorithm framework
git clone [email protected]:dracuxan/genetic.git
Log | Files | Refs | README

lib.rs (456B)


      1 use rustler::NifResult;
      2 use std::sync::Mutex;
      3 
      4 static RNG_STATE: Mutex<(u32, u32, u32)> = Mutex::new((123_456_789, 362_436_069, 52_128_629));
      5 
      6 #[rustler::nif]
      7 fn xor96() -> NifResult<u32> {
      8     let mut state = RNG_STATE.lock().unwrap();
      9 
     10     let (ref mut x, ref mut y, ref mut z) = *state;
     11 
     12     let t = *x ^ (*x << 10);
     13     *x = *y;
     14     *y = *z;
     15     *z = (*z ^ (*z >> 26)) ^ (t ^ (t >> 5));
     16 
     17     Ok(*z)
     18 }
     19 
     20 rustler::init!("Elixir.Genetic.Random", [xor96]);