pub trait SampleUniform: Sized {
    // Required method
    fn sample_standard_uniform(constant_time: bool) -> Fallible<Self>;
}
Expand description

Sample exactly from the uniform distribution.

Required Methods§

source

fn sample_standard_uniform(constant_time: bool) -> Fallible<Self>

Proof Definition

Return Err(e) if there is insufficient system entropy, or Ok(sample), where sample is a draw from Uniform[0,1).

For non-uniform data types like floats, the probability of sampling each value is proportional to the distance to the next neighboring float.

Example
// valid draw from Unif[0,1)
use opendp::traits::samplers::SampleUniform;
let unif = f64::sample_standard_uniform(false);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T, B> SampleUniform for T
where T: SampleMantissa<Bits = B>, B: ExactIntCast<usize> + Sub<Output = B> + One, usize: ExactIntCast<B>,

This algorithm is taken from Mironov (2012) and is important for making some of the guarantees in the paper.

The idea behind the uniform sampling is to first sample a “precision band”. Each band is a range of floating point numbers with the same level of arithmetic precision and is situated between powers of two. A band is sampled with probability relative to the unit of least precision using the Geometric distribution. That is, the uniform sampler will generate the band [1/2,1) with probability 1/2, [1/4,1/2) with probability 1/4, and so on.

Once the precision band has been selected, floating numbers numbers are generated uniformly within the band by generating a 52-bit mantissa uniformly at random.