Compare commits
No commits in common. "022ff76715fcf88bd7225dff96b05e8503830830" and "237468f28aa2fa1f26252d4e9e5cce9f74fc952a" have entirely different histories.
022ff76715
...
237468f28a
30
README.md
30
README.md
@ -6,26 +6,14 @@ This was a test to determine if random numbers follow [Benford's Law](https://en
|
|||||||
|
|
||||||
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:
|
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:
|
||||||
|
|
||||||
```shell
|
1. 11105630
|
||||||
$ ./benfords-law.exe
|
2. 11110535
|
||||||
2020/11/14 10:24:18 generating numbers...
|
3. 11112084
|
||||||
2020/11/14 10:24:19 18% completed generating and analyzing samples
|
4. 11113667
|
||||||
2020/11/14 10:24:20 37% completed generating and analyzing samples
|
5. 11120216
|
||||||
2020/11/14 10:24:21 56% completed generating and analyzing samples
|
6. 11106549
|
||||||
2020/11/14 10:24:22 75% completed generating and analyzing samples
|
7. 11108623
|
||||||
2020/11/14 10:24:23 93% completed generating and analyzing samples
|
8. 11114813
|
||||||
2020/11/14 10:24:24 done.
|
9. 11107883
|
||||||
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 natural data is generated following a power law, which is common in nature.
|
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 natural data is generated following a power law, which is common in nature.
|
||||||
|
|
6
main.go
6
main.go
@ -27,7 +27,7 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
<-statusTicker.C
|
<-statusTicker.C
|
||||||
percentCompleted := (currentSample * 100) / numSamples
|
percentCompleted := (currentSample * 100) / numSamples
|
||||||
log.Printf("%d%% completed generating and analyzing samples", percentCompleted)
|
log.Printf("%d %% completed generating and analyzing samples", percentCompleted)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func main() {
|
|||||||
|
|
||||||
// output results
|
// output results
|
||||||
for digitMinusOne, count := range results {
|
for digitMinusOne, count := range results {
|
||||||
fmt.Printf("%d: %d (%f%%)\n", digitMinusOne+1, count, float64(count*100)/float64(numSamples))
|
fmt.Printf("%d: %d\n", digitMinusOne+1, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Press 'Enter' to continue...")
|
fmt.Print("Press 'Enter' to continue...")
|
||||||
@ -61,12 +61,10 @@ func generatorWorker(returnChannel chan int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// firstDigit returns the first/leftmost digit of the base10 representation of an integer
|
|
||||||
func firstDigit(x int) int {
|
func firstDigit(x int) int {
|
||||||
return int(math.Abs(float64(x)) / math.Pow(10, float64(numDigits(x)-1)))
|
return int(math.Abs(float64(x)) / math.Pow(10, float64(numDigits(x)-1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// numDigits returns the number of digits
|
|
||||||
func numDigits(x int) int {
|
func numDigits(x int) int {
|
||||||
if x == 0 {
|
if x == 0 {
|
||||||
return 1
|
return 1
|
||||||
|
Loading…
Reference in New Issue
Block a user