Skip to content

Instantly share code, notes, and snippets.

@steveshogren
Last active December 26, 2015 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveshogren/7100597 to your computer and use it in GitHub Desktop.
Save steveshogren/7100597 to your computer and use it in GitHub Desktop.
(defn roll-fate-die []
(- (rand-int 3) 1))
(defn test-fate-percentages [rolls-count]
(let [rolls (map (fn [x]
(reduce + (map (fn [x] (roll-fate-die))
(range 4))))
(range rolls-count))]
(map (fn [x] [(first x)
(int (* 100 (/ (count (second x)) rolls-count)))])
(group-by (fn [x] x) rolls))))
(test-fate-percentages 100000)
;; => ([-1 19] [0 23] [1 19] [-2 12] [2 12] [-3 4] [3 4] [-4 1] [4 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment