binius_core/fiat_shamir/
sampling.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2024 Irreducible Inc.
// Copyright (c) 2024 The Plonky3 authors

//! Traits used to sample random values in a public-coin interactive protocol.
//!
//! These interfaces are taken from [p3_challenger](https://github.com/Plonky3/Plonky3/blob/main/challenger/src/lib.rs) in [Plonky3].
//!
//! [Plonky3]: <https://github.com/plonky3/plonky3>

use std::array;

#[auto_impl::auto_impl(&mut)]
pub trait CanSample<T> {
	fn sample(&mut self) -> T;

	fn sample_array<const N: usize>(&mut self) -> [T; N] {
		array::from_fn(|_| self.sample())
	}

	fn sample_vec(&mut self, n: usize) -> Vec<T> {
		(0..n).map(|_| self.sample()).collect()
	}
}

#[auto_impl::auto_impl(&mut)]
pub trait CanSampleBits<T> {
	fn sample_bits(&mut self, bits: usize) -> T;
}