A quick test to show that Benford's Law does not work for data that is random numbers. It does however work very well for data which is generated following a power law. https://en.wikipedia.org/wiki/Benford%27s_law
Go to file
Steven Polley 56f3a5ed3a Clean up project 2020-11-14 20:12:11 -07:00
.gitignore Clean up project 2020-11-14 20:12:11 -07:00
README.md clarification for which data which Benford's law applies 2020-11-15 02:53:37 +00:00
main.go Clean up project 2020-11-14 20:12:11 -07:00

README.md

benfords-law

This was a test to determine if random numbers follow Benford's Law. I suspect it has more to do with the distribution real life data collected from than truly random numbers. If this is true, maybe this is why it works for fraud detection.

Results

With One-Hundred-Million samples of random numbers between 0 and 9,999,999,999,999,999, the number of leading digits was the following:

$ ./benfords-law.exe
2020/11/14 10:24:18 generating numbers...
2020/11/14 10:24:19 18% completed generating and analyzing samples
2020/11/14 10:24:20 37% completed generating and analyzing samples
2020/11/14 10:24:21 56% completed generating and analyzing samples
2020/11/14 10:24:22 75% completed generating and analyzing samples
2020/11/14 10:24:23 93% completed generating and analyzing samples
2020/11/14 10:24:24 done.
1: 1108503 (11.085030%)
2: 1111584 (11.115840%)
3: 1111726 (11.117260%)
4: 1111122 (11.111220%)
5: 1110443 (11.104430%)
6: 1111248 (11.112480%)
7: 1111496 (11.114960%)
8: 1111777 (11.117770%)
9: 1112101 (11.121010%)
Press 'Enter' to continue...

This shows that Benford's law only works when the data is not random, such as natural data gathered in real life. This is because for data which Benford's law does work, it's natural data generated following a power law, which is quite common in nature.