pub struct BenfordSampler { /* private fields */ }Expand description
Sampler that produces amounts following Benford’s Law distribution.
The sampler derives the order-of-magnitude of each amount from the
configured log-normal distribution (parameterised by
lognormal_mu / lognormal_sigma on
AmountDistributionConfig) and then overrides the first
significant digit to match the requested Benford / anti-Benford
distribution. This produces realistic per-amount magnitudes that
match routine traffic, while preserving the first-digit
statistical signature that fraud-detection consumers care about.
(Earlier versions sampled magnitude uniformly across
[log10(min_amount), log10(max_amount)]. That over-represented
the high tail and caused account-level balances to drift into
numerically unsafe territory under audit-group + 12-month +
hundred_k retail configs — see GitHub issue #185.)
Implementations§
Source§impl BenfordSampler
impl BenfordSampler
Sourcepub fn new(seed: u64, config: AmountDistributionConfig) -> Self
pub fn new(seed: u64, config: AmountDistributionConfig) -> Self
Create a new Benford sampler with the given seed and amount configuration.
Sourcepub fn sample_with_first_digit(&mut self, first_digit: u8) -> Decimal
pub fn sample_with_first_digit(&mut self, first_digit: u8) -> Decimal
Sample an amount with a specific first digit.
The order-of-magnitude is drawn from the parent log-normal
distribution (clamped to [min_amount, max_amount]), which
matches the magnitude distribution of routine traffic. The
first significant digit is then forced to first_digit,
preserving the Benford / anti-Benford statistical signature
that consumers expect. This avoids the uniform-magnitude
over-representation of the high tail that previously inflated
account-level balances into the 10^15+ range under
audit-group + multi-period retail configs (issue #185).