pub fn sample_implied_distribution(
f: impl Fn(u64) -> usize,
rng: &mut impl Rng,
) -> impl Iterator<Item = u64> + '_
Expand description
Returns an infinite iterator of samples from the implied distribution of the given code length function. The function f should be the len function of the code.
This code works only with monotonic non decreasing len functions and the codes are limited to 128 bits as we cannot write more than 64 bits at once.
ยงExample
use dsi_bitstream::utils::sample_implied_distribution;
use dsi_bitstream::codes::len_gamma;
use rand::SeedableRng;
use rand::rngs::SmallRng;
let mut rng = SmallRng::seed_from_u64(42);
let vals: Vec<u64> = sample_implied_distribution(len_gamma, &mut rng)
.take(1000).collect::<Vec<_>>();
assert_eq!(vals.len(), 1000);