Crates.io | benford |
lib.rs | benford |
version | 0.1.2 |
source | src |
created_at | 2023-01-29 08:15:08.635102 |
updated_at | 2023-01-31 10:48:27.083627 |
description | library to test the Benford-ness of a given set of numbers |
homepage | |
repository | https://github.com/janstarke/benford |
max_upload_size | |
id | 770790 |
size | 63,678 |
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
]
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());
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));
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