Skip to content

Instantly share code, notes, and snippets.

@vilmibm
Created October 15, 2013 01:22
Show Gist options
  • Save vilmibm/6985139 to your computer and use it in GitHub Desktop.
Save vilmibm/6985139 to your computer and use it in GitHub Desktop.
I forgot my dice during d&d tonight so I wrote this.
(defmacro roll [rolls _ sides & body]
`(+ (if (nil? ~body) 0 ~body) (reduce + (repeatedly ~rolls #(+ 1 (rand-int ~sides))))))
(roll 1 d 4) ; dagger
(roll 1 d 20 + 6) ; initiative
(roll 4 d 4 + 4) ; 7th level magic missle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment