MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / probability_sample

Function probability_sample

crates/runtime/src/sim/rng.rs:188–198  ·  view source on GitHub ↗
(value: u64, probability: f64)

Source from the content-addressed store, hash-verified

186pub(crate) struct DeterminismLog(Vec<u8>);
187
188fn probability_sample(value: u64, probability: f64) -> bool {
189 if probability <= 0.0 {
190 return false;
191 }
192 if probability >= 1.0 {
193 return true;
194 }
195
196 let unit = (value >> 11) as f64 * (1.0 / ((1u64 << 53) as f64));
197 unit < probability
198}
199
200fn checksum(value: u64) -> u8 {
201 value.to_ne_bytes().into_iter().fold(0, |acc, byte| acc ^ byte)

Callers 1

sample_probabilityMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…