use crate::*;
use arcis_interpreter_proc_macros::encrypted_library;
#[encrypted_library]
mod arcis_library {
struct ArcisRNGUtils;
impl ArcisRNGUtils {
#[arcis_circuit = "bitwise_and"]
fn bitwise_and(a: u128, b: u128) -> u128 {}
#[arcis_circuit = "lowest_bigger_power_of_two_minus_one"]
fn lowest_bigger_power_of_two_minus_one(a: u128) -> u128 {}
}
impl ArcisRNG {
fn gen_and_reject(max: u128) -> (u128, bool) {
let lbpotmo = ArcisRNGUtils::lowest_bigger_power_of_two_minus_one(max);
let rand = Self::gen_integer_from_width(128);
let rand = ArcisRNGUtils::bitwise_and(rand, lbpotmo);
if rand <= max {
(rand, true)
} else {
(0, false)
}
}
pub fn gen_integer_in_range(min: u128, max: u128, n_attempts: usize) -> (u128, bool) {
let range = max - min;
let mut res = 0;
let mut success = false;
for _ in 0..n_attempts {
let (r, s) = Self::gen_and_reject(range);
if !success {
res = r;
success = s;
}
}
(res + min, success)
}
}
}