Skip to content

Instantly share code, notes, and snippets.

@newmen
Created June 26, 2026 15:50
Show Gist options
  • Select an option

  • Save newmen/cd078b1cfb7bc470529a33b9b034de9c to your computer and use it in GitHub Desktop.

Select an option

Save newmen/cd078b1cfb7bc470529a33b9b034de9c to your computer and use it in GitHub Desktop.
dates-normal-destribution.clj
(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