Skip to main content

num_bigint/
bigrand.rs

1//! Randomization of big integers
2
3#[cfg(any(feature = "rand_0_10", feature = "rand_0_9"))]
4mod structs {
5    use crate::{BigInt, BigUint};
6
7    /// The back-end implementing rand's `UniformSampler` for [`BigUint`].
8    #[derive(Clone, Debug)]
9    pub struct UniformBigUint {
10        pub(super) base: BigUint,
11        pub(super) len: BigUint,
12    }
13
14    /// The back-end implementing rand's `UniformSampler` for [`BigInt`].
15    #[derive(Clone, Debug)]
16    pub struct UniformBigInt {
17        pub(super) base: BigInt,
18        pub(super) len: BigUint,
19    }
20
21    /// A random distribution for [`BigUint`] and [`BigInt`] values of a particular bit size.
22    #[derive(Clone, Copy, Debug)]
23    pub struct RandomBits {
24        pub(super) bits: u64,
25    }
26
27    impl RandomBits {
28        #[inline]
29        pub fn new(bits: u64) -> RandomBits {
30            RandomBits { bits }
31        }
32    }
33}
34
35#[cfg(any(feature = "rand_0_10", feature = "rand_0_9"))]
36pub use structs::{RandomBits, UniformBigInt, UniformBigUint};
37
38#[cfg(feature = "rand_core_0_10")]
39#[path = "bigrand"]
40mod impl_0_10 {
41    use rand_core_0_10::Rng;
42
43    mod traits;
44
45    pub use traits::BigRng;
46
47    #[cfg(feature = "rand_0_10")]
48    use rand_0_10 as rand;
49
50    #[cfg(feature = "rand_0_10")]
51    #[cfg_attr(docsrs, doc(cfg(feature = "rand_0_10")))]
52    mod distr;
53}
54
55#[cfg(feature = "rand_core_0_10")]
56pub use impl_0_10::BigRng as BigRng010;
57
58#[cfg(feature = "rand_core_0_9")]
59#[path = "bigrand"]
60mod impl_0_9 {
61    use rand_core_0_9::RngCore as Rng;
62
63    mod traits;
64
65    pub use traits::BigRng;
66
67    #[cfg(feature = "rand_0_9")]
68    use rand_0_9 as rand;
69
70    #[cfg(feature = "rand_0_9")]
71    #[cfg_attr(docsrs, doc(cfg(feature = "rand_0_9")))]
72    mod distr;
73}
74
75#[cfg(feature = "rand_core_0_9")]
76pub use impl_0_9::BigRng as BigRng09;