use crate::rng::Rng64;
use crate::rng64::TwistedGFSR;
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_new(seed: u64) -> *mut TwistedGFSR {
Box::into_raw(Box::new(TwistedGFSR::new(seed)))
}
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_free(ptr: *mut TwistedGFSR) {
if !ptr.is_null() {
unsafe { drop(Box::from_raw(ptr)) };
}
}
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_next_u64s(ptr: *mut TwistedGFSR, out: *mut u64, count: usize) {
unsafe {
let rng = &mut *ptr;
crate::_internal::fill_with(out, count, || rng.nextu());
}
}
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_next_f64s(ptr: *mut TwistedGFSR, out: *mut f64, count: usize) {
unsafe {
let rng = &mut *ptr;
crate::_internal::fill_with(out, count, || rng.nextf());
}
}
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_rand_i64s(
ptr: *mut TwistedGFSR,
out: *mut i64,
count: usize,
min: i64,
max: i64,
) {
unsafe {
let rng = &mut *ptr;
crate::_internal::fill_with(out, count, || rng.randi(min, max));
}
}
#[unsafe(no_mangle)]
pub extern "C" fn twisted_gfsr_rand_f64s(
ptr: *mut TwistedGFSR,
out: *mut f64,
count: usize,
min: f64,
max: f64,
) {
unsafe {
let rng = &mut *ptr;
crate::_internal::fill_with(out, count, || rng.randf(min, max));
}
}