Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/utils/sample/binomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rand_distr::{Binomial, Distribution};
/// let sample = bin_sampler.sample();
///
/// assert!(0 <= sample);
/// assert!(sample < n);
/// assert!(sample <= n);
Copy link
Member

@3pmile 3pmile Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See below/ above

/// ```
pub struct BinomialSampler {
distr: Binomial,
Expand Down Expand Up @@ -91,8 +91,7 @@ impl BinomialSampler {
Ok(Self { distr, rng })
}

/// Computes a uniformly chosen [`Z`] sample in `[0, interval_size)`
/// using rejection sampling that accepts samples with probability at least 1/2.
/// Samples a [`Z`] according to the binomial distribution `Bin(n, p)`.
///
/// # Examples
/// ```
Expand All @@ -105,7 +104,7 @@ impl BinomialSampler {
/// let sample = bin_sampler.sample();
///
/// assert!(0 <= sample);
/// assert!(sample < n);
Comment on lines 107 to -108
Copy link
Member

@3pmile 3pmile Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distribution explicitly samples [0, interval_size) per documentation. if we want [1, interval_size] please change that aswell, otehrwise we start counting at 0 and therefore n is not part of the intervall.

/// assert!(sample <= n);
/// ```
pub fn sample(&mut self) -> Z {
Z::from(self.distr.sample(&mut self.rng))
Expand Down
Loading