benford

Crates.iobenford
lib.rsbenford
version0.1.2
sourcesrc
created_at2023-01-29 08:15:08.635102
updated_at2023-01-31 10:48:27.083627
descriptionlibrary to test the Benford-ness of a given set of numbers
homepage
repositoryhttps://github.com/janstarke/benford
max_upload_size
id770790
size63,678
Jan Starke (janstarke)

documentation

README

benford

This crate provides a way to test if some given set of numbers conforms to Benford's law

Currently, only the first digit is being used. You can use your own method of mapping a number to a digit, by implementing [BenfordClass]

Example 1: Fibonacci numbers are Benford ...

use benford::{BenfordTester, FirstDigitBase10, Fibonacci};

let mut tester = BenfordTester::default();
let mut fibonacci = Fibonacci::<u64>::default();
for val in fibonacci {
    if val != 0 {
        tester.add_sample::<FirstDigitBase10>(val.into());
    }
}
assert!(tester.is_benford());

Example 2: ... but only with limited confidence

if your test set is too small

use benford::{Alpha, BenfordTester, FirstDigitBase10, Fibonacci};

let mut tester = BenfordTester::default();
let mut fibonacci = Fibonacci::<u16>::default();
for val in fibonacci {
    if val != 0 {
        tester.add_sample::<FirstDigitBase10>(val.into());
    }
}
assert!(! tester.is_benford());
assert!(tester.is_benford_with_alpha(Alpha::Point9));

Example 3: Natural numbers are not Benford

use benford::{BenfordTester, FirstDigitBase10};

let mut tester = BenfordTester::default();
for val in 1..u16::MAX {
    tester.add_sample::<FirstDigitBase10>(val.into());
}
assert!(! tester.is_benford())

License: GPL-3.0

Commit count: 7

cargo fmt