twenty_first/math/
other.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use rand::distributions::Distribution;
use rand::distributions::Standard;
use rand::Rng;

/// Generate `n` random elements using [`rand::thread_rng()`].
///
/// For example implementations of the [`Distribution`] trait for [`Standard`], see
/// [`BFieldElement`][bfe] or [`XFieldElement`][xfe].
///
/// [bfe]: crate::prelude::BFieldElement
/// [xfe]: crate::prelude::XFieldElement
pub fn random_elements<T>(n: usize) -> Vec<T>
where
    Standard: Distribution<T>,
{
    rand::thread_rng().sample_iter(Standard).take(n).collect()
}