binius_core/fiat_shamir/sampling.rs
1// Copyright 2024-2025 Irreducible Inc.
2// Copyright (c) 2024 The Plonky3 authors
3
4//! Traits used to sample random values in a public-coin interactive protocol.
5//!
6//! These interfaces are taken from [p3_challenger](https://github.com/Plonky3/Plonky3/blob/main/challenger/src/lib.rs) in [Plonky3].
7//!
8//! [Plonky3]: <https://github.com/plonky3/plonky3>
9
10use std::array;
11
12#[auto_impl::auto_impl(&mut)]
13pub trait CanSample<T> {
14 fn sample(&mut self) -> T;
15
16 fn sample_array<const N: usize>(&mut self) -> [T; N] {
17 array::from_fn(|_| self.sample())
18 }
19
20 fn sample_vec(&mut self, n: usize) -> Vec<T> {
21 (0..n).map(|_| self.sample()).collect()
22 }
23}
24
25#[auto_impl::auto_impl(&mut)]
26pub trait CanSampleBits<T> {
27 fn sample_bits(&mut self, bits: usize) -> T;
28}