Created
August 15, 2020 06:27
-
-
Save ryukinix/c87b39fffd64b2798f4a8ed961c0e2d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; pseudo-random numbers don't follows Benford's Law. | |
(ql:quickload :cl-spark) | |
(defun random-numbers (max count) | |
(loop repeat count | |
for n := (random max) | |
when (plusp n) | |
collect n)) | |
(defun most-significant-digit (x) | |
(nth-value 0 (floor (/ x (expt 10 (floor (log x 10))))))) | |
(defun histogram (numbers) | |
(loop with hist := (make-array 9 :initial-element 0) | |
for x in numbers | |
do (incf (aref hist (1- x))) | |
finally (return hist))) | |
(defun main (&optional (max 1000000) (count 1000000)) | |
(let* ((numbers (random-numbers max count)) | |
(digits (mapcar #'most-significant-digit numbers)) | |
(hist (histogram digits))) | |
(spark:spark (coerce hist 'list)))) | |
#| | |
CL-USER> (main) | |
"▅▇▇▆▄▁▄█▄" | |
CL-USER> (main) | |
"▆▅▂▁▆▁▂▁█" | |
CL-USER> (main) | |
"▄▁█▁▃▅▄▄▂" | |
CL-USER> (main) | |
"▃▅▂▁▁█▂▃▂" | |
CL-USER> (main) | |
"▁▆▅█▄▂▆▅▅" | |
CL-USER> (main) | |
"▂▃▅█▂▁▃▂▂" | |
CL-USER> (main) | |
"▅▅▃▁▂█▅▃▁" | |
CL-USER> (main) | |
"█▆▅▃▇▃▃▃▁" | |
CL-USER> (main) | |
"▂▇▇█▇▃▇▃▁" | |
CL-USER> (main) | |
"▇▇▂▁▄▇▄█▆" | |
CL-USER> (main) | |
"▆▁▄▂▃█▆▆▇" | |
CL-USER> (main) | |
"▁▁▆▂▃▂▃█▇" | |
CL-USER> (main) | |
"▂▄▄█▁▆▂▄▆" | |
CL-USER> (main) | |
"▅▄▇▅▄█▁▃▂" | |
CL-USER> (main) | |
"▁▅▄▃▃▄▂▄█" | |
CL-USER> (main) | |
"▃▅▂▃█▅▁▃▆" | |
|# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment