Created
June 26, 2026 15:50
-
-
Save newmen/cd078b1cfb7bc470529a33b9b034de9c to your computer and use it in GitHub Desktop.
dates-normal-destribution.clj
This file contains hidden or 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
| (ns dates-normal-distribution | |
| (:import [java.util.concurrent ThreadLocalRandom] | |
| [java.time LocalDate])) | |
| (defn next-gaussian | |
| [] | |
| (let [k 0.166 | |
| r (.nextGaussian (ThreadLocalRandom/current)) | |
| x (+ 0.5 (* r k))] | |
| (if (<= 0 x 1) | |
| x | |
| (recur)))) | |
| (defn get-random-date | |
| [] | |
| (let [d (+ (* 90 365 (next-gaussian)) 3650) | |
| n (LocalDate/now)] | |
| (.minusDays n d))) | |
| (defn get-random-table | |
| [n] | |
| (loop [acc {} | |
| n n] | |
| (if (zero? n) | |
| (sort-by first acc) | |
| (let [x (get-random-date) | |
| y (.getYear x)] | |
| (recur (update acc y (fnil inc 0)) | |
| (dec n)))))) | |
| (comment | |
| (clojure.pprint/pprint (get-random-table 80000000)) | |
| (get-random-date) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment