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).
Auto Trait Implementations§
impl Freeze for BenfordSampler
impl RefUnwindSafe for BenfordSampler
impl Send for BenfordSampler
impl Sync for BenfordSampler
impl Unpin for BenfordSampler
impl UnsafeUnpin for BenfordSampler
impl UnwindSafe for BenfordSampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.