MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / sample

Method sample

nodedb/src/engine/random/alias.rs:89–93  ·  view source on GitHub ↗

Sample one index (O(1) per call).

(&self, rng: &mut SeedableRng)

Source from the content-addressed store, hash-verified

87
88 /// Sample one index (O(1) per call).
89 pub fn sample(&self, rng: &mut SeedableRng) -> usize {
90 let i = rng.gen_range(self.n as u64) as usize;
91 let u = rng.gen_f64();
92 if u < self.prob[i] { i } else { self.alias[i] }
93 }
94
95 /// Sample `count` indices without replacement.
96 ///

Callers 6

uniform_distributionFunction · 0.80
skewed_distributionFunction · 0.80
deterministic_with_seedFunction · 0.80

Calls 2

gen_rangeMethod · 0.80
gen_f64Method · 0.80

Tested by 4

uniform_distributionFunction · 0.64
skewed_distributionFunction · 0.64
deterministic_with_seedFunction · 0.64