wip on RLWE

This commit is contained in:
Jean-Philippe Bossuat
2025-02-10 23:43:01 +01:00
parent 0519510667
commit ec6968d52a
11 changed files with 310 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaCha8Rng;
use rand_core::RngCore;
use rand_core::{OsRng, RngCore};
const MAXF64: f64 = 9007199254740992.0;
@@ -8,6 +8,12 @@ pub struct Source {
source: ChaCha8Rng,
}
pub fn new_seed() -> [u8; 32] {
let mut seed = [0u8; 32];
OsRng.fill_bytes(&mut seed);
seed
}
impl Source {
pub fn new(seed: [u8; 32]) -> Source {
Source {
@@ -21,6 +27,10 @@ impl Source {
seed
}
pub fn branch(&mut self) -> Self {
Source::new(self.new_seed())
}
#[inline(always)]
pub fn next_u64n(&mut self, max: u64, mask: u64) -> u64 {
let mut x: u64 = self.next_u64() & mask;