use std::fmt;
use crate::prim::{*, typ::*, mpz::*, gmp::*};
#[allow(non_camel_case_types)]
pub type gmp_randalg_t = int_t;
pub const GMP_RAND_ALG_DEFAULT: gmp_randalg_t = 0;
pub const GMP_RAND_ALG_LC: gmp_randalg_t = 0;
#[repr(C)]
pub struct gmp_randstate_struct {
pub _mp_seed: __mpz_struct,
pub _mp_alg: gmp_randalg_t,
pub _mp_algdata_union_mp_lc: mp_t
}
impl SNew for gmp_randstate_struct {
#[inline]
fn new() -> Self {
gmp_randstate_struct {
_mp_seed: mpz_s::from(0), _mp_alg: GMP_RAND_ALG_DEFAULT,
_mp_algdata_union_mp_lc: 0 as mp_t
}
}
}
impl Drop for gmp_randstate_struct {
fn drop(&mut self) {
}
}
impl AsPtr for gmp_randstate_struct {}
impl AsPtrMut for gmp_randstate_struct {}
impl gmp_randstate_struct {
#[inline]
pub fn clear(&mut self) -> () {
gmp_randclear(self)
}
#[inline]
pub fn init(sz: mp_bitcnt_t) -> Self {
let mut t = randstate_s::new();
gmp_randinit(&mut t, GMP_RAND_ALG_LC, sz);
t
}
#[inline]
pub fn init_set(s: randstate_r) -> Self {
let mut t = randstate_s::new();
gmp_randinit_set(&mut t, s);
t
}
#[inline]
pub fn init_default() -> Self {
let mut t = randstate_s::new();
gmp_randinit_default(&mut t);
t
}
#[inline]
pub fn init_mt() -> Self {
let mut t = randstate_s::new();
gmp_randinit_mt(&mut t);
t
}
#[inline]
pub fn init_lc_2exp(a: mpz_r, c: ui_t, m2e: mp_bitcnt_t) -> Self {
let mut t = randstate_s::new();
gmp_randinit_lc_2exp(&mut t, a, c, m2e);
t
}
#[inline]
pub fn init_lc_2exp_size(sz: mp_bitcnt_t) -> (Self, int_t) {
let mut t = randstate_s::new();
let i = gmp_randinit_lc_2exp_size(&mut t, sz);
(t, i)
}
#[inline]
pub fn seed(&mut self, seed: mpz_t) -> &mut Self {
gmp_randseed(self, seed);
self
}
#[inline]
pub fn seed_ui(&mut self, seed: ui_t) -> &mut Self {
gmp_randseed_ui(self, seed);
self
}
#[inline]
pub fn urandomb_ui(r: randstate_t, nbits: ui_t) -> ui_t {
gmp_urandomb_ui(r, nbits)
}
#[inline]
pub fn urandomm_ui(r: randstate_t, n: ui_t) -> ui_t {
gmp_urandomm_ui(r, n)
}
}
impl fmt::Debug for gmp_randstate_struct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "seed({}) alg({}) data({:016x})",
self._mp_seed, self._mp_alg, self._mp_algdata_union_mp_lc as usize)
}
}
impl fmt::Display for gmp_randstate_struct {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self._mp_seed)
}
}
#[allow(non_camel_case_types)]
pub type randstate_s = gmp_randstate_struct; #[allow(non_camel_case_types)]
pub type randstate_t<'a> = &'a mut randstate_s; #[allow(non_camel_case_types)]
pub type randstate_r<'a> = &'a randstate_s;
#[inline]
pub fn gmp_randclear(r: randstate_t) -> () {
unsafe { __gmp_randclear(r) }
}
#[inline]
pub fn gmp_randinit(r: randstate_t, _a: gmp_randalg_t, sz: mp_bitcnt_t) -> () {
unsafe { __gmp_randinit_lc_2exp_size(r, sz); } }
#[inline]
pub fn gmp_randinit_set(r: randstate_t, s: randstate_r) -> () {
unsafe { __gmp_randinit_set(r, s) }
}
#[inline]
pub fn gmp_randinit_default(r: randstate_t) -> () {
unsafe { __gmp_randinit_default(r) }
}
#[inline]
pub fn gmp_randinit_mt(r: randstate_t) -> () {
unsafe { __gmp_randinit_mt(r) }
}
#[inline]
pub fn gmp_randinit_lc_2exp(r: randstate_t,
a: mpz_r, c: ui_t, m2e: mp_bitcnt_t) -> () {
unsafe { __gmp_randinit_lc_2exp(r, a, c, m2e) }
}
#[inline]
pub fn gmp_randinit_lc_2exp_size(r: randstate_t, sz: mp_bitcnt_t) -> int_t {
unsafe { __gmp_randinit_lc_2exp_size(r, sz) }
}
#[inline]
pub fn gmp_randseed(r: randstate_t, seed: mpz_t) -> () {
unsafe { __gmp_randseed(r, seed) }
}
#[inline]
pub fn gmp_randseed_ui(r: randstate_t, seed: ui_t) -> () {
unsafe { __gmp_randseed_ui(r, seed) }
}
#[inline]
pub fn gmp_urandomb_ui(r: randstate_t, nbits: ui_t) -> ui_t {
unsafe { __gmp_urandomb_ui(r, nbits) }
}
#[inline]
pub fn gmp_urandomm_ui(r: randstate_t, n: ui_t) -> ui_t {
unsafe { __gmp_urandomm_ui(r, n) }
}