Simplified code by using private def and defn versions and rand-nth function