crypto_bigint/int/
rand.rs1use rand_core::RngCore;
4
5use crate::{Int, Random, RandomBits, RandomBitsError};
6
7use super::Uint;
8
9impl<const LIMBS: usize> Random for Int<LIMBS> {
10 fn random(rng: &mut (impl RngCore + ?Sized)) -> Self {
12 Self(Uint::random(rng))
13 }
14}
15
16impl<const LIMBS: usize> RandomBits for Int<LIMBS> {
17 fn try_random_bits(
18 rng: &mut (impl RngCore + ?Sized),
19 bit_length: u32,
20 ) -> Result<Self, RandomBitsError> {
21 Self::try_random_bits_with_precision(rng, bit_length, Self::BITS)
22 }
23
24 fn try_random_bits_with_precision(
25 rng: &mut (impl RngCore + ?Sized),
26 bit_length: u32,
27 bits_precision: u32,
28 ) -> Result<Self, RandomBitsError> {
29 Uint::try_random_bits_with_precision(rng, bit_length, bits_precision).map(Self)
30 }
31}