updated rand to latest versions

This commit is contained in:
Jean-Philippe Bossuat
2025-04-24 18:13:57 +02:00
parent 640387d840
commit b33a96e80a
4 changed files with 49 additions and 26 deletions

52
Cargo.lock generated
View File

@@ -49,6 +49,12 @@ dependencies = [
"utils", "utils",
] ]
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.16.0" version = "3.16.0"
@@ -206,12 +212,13 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.15" version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"r-efi",
"wasi", "wasi",
] ]
@@ -388,21 +395,26 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rand" name = "r-efi"
version = "0.8.5" version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "rand"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97"
dependencies = [ dependencies = [
"libc",
"rand_chacha", "rand_chacha",
"rand_core", "rand_core",
] ]
[[package]] [[package]]
name = "rand_chacha" name = "rand_chacha"
version = "0.3.1" version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core", "rand_core",
@@ -410,18 +422,18 @@ dependencies = [
[[package]] [[package]]
name = "rand_core" name = "rand_core"
version = "0.6.4" version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [ dependencies = [
"getrandom", "getrandom",
] ]
[[package]] [[package]]
name = "rand_distr" name = "rand_distr"
version = "0.4.3" version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" checksum = "6a8615d50dcf34fa31f7ab52692afec947c4dd0ab803cc87cb3b0b4570ff7463"
dependencies = [ dependencies = [
"num-traits", "num-traits",
"rand", "rand",
@@ -602,9 +614,12 @@ dependencies = [
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
@@ -761,6 +776,15 @@ version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]] [[package]]
name = "zerocopy" name = "zerocopy"
version = "0.7.35" version = "0.7.35"

View File

@@ -4,9 +4,9 @@ members = ["base2k", "rlwe", "sampling", "utils"]
[workspace.dependencies] [workspace.dependencies]
rug = "1.27" rug = "1.27"
rand = "0.8.4" rand = "0.9.1"
rand_chacha = "0.3.1" rand_chacha = "0.9.0"
rand_core = "0.6.4" rand_core = "0.9.3"
rand_distr = "0.4.3" rand_distr = "0.5.1"
itertools = "0.14.0" itertools = "0.14.0"
criterion = "0.5.1" criterion = "0.5.1"

View File

@@ -5,7 +5,7 @@ use crate::{BACKEND, Module, VecZnx, VecZnxDft, assert_alignement};
use crate::{Infos, alloc_aligned, cast_mut}; use crate::{Infos, alloc_aligned, cast_mut};
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use rand_core::RngCore; use rand_core::RngCore;
use rand_distr::{Distribution, WeightedIndex}; use rand_distr::{Distribution, weighted::WeightedIndex};
use sampling::source::Source; use sampling::source::Source;
pub struct Scalar { pub struct Scalar {

View File

@@ -1,6 +1,6 @@
use rand_chacha::ChaCha8Rng; use rand_chacha::ChaCha8Rng;
use rand_chacha::rand_core::SeedableRng; use rand_chacha::rand_core::SeedableRng;
use rand_core::{OsRng, RngCore}; use rand_core::{OsRng, RngCore, TryRngCore};
const MAXF64: f64 = 9007199254740992.0; const MAXF64: f64 = 9007199254740992.0;
@@ -10,7 +10,7 @@ pub struct Source {
pub fn new_seed() -> [u8; 32] { pub fn new_seed() -> [u8; 32] {
let mut seed = [0u8; 32]; let mut seed = [0u8; 32];
OsRng.fill_bytes(&mut seed); OsRng.try_fill_bytes(&mut seed).unwrap();
seed seed
} }
@@ -44,6 +44,10 @@ impl Source {
pub fn next_f64(&mut self, min: f64, max: f64) -> f64 { pub fn next_f64(&mut self, min: f64, max: f64) -> f64 {
min + ((self.next_u64() << 11 >> 11) as f64) / MAXF64 * (max - min) min + ((self.next_u64() << 11 >> 11) as f64) / MAXF64 * (max - min)
} }
pub fn next_i64(&mut self) -> i64{
self.next_u64() as i64
}
} }
impl RngCore for Source { impl RngCore for Source {
@@ -61,9 +65,4 @@ impl RngCore for Source {
fn fill_bytes(&mut self, bytes: &mut [u8]) { fn fill_bytes(&mut self, bytes: &mut [u8]) {
self.source.fill_bytes(bytes) self.source.fill_bytes(bytes)
} }
#[inline(always)]
fn try_fill_bytes(&mut self, bytes: &mut [u8]) -> Result<(), rand_core::Error> {
self.source.try_fill_bytes(bytes)
}
} }