Friday, February 28, 2014

99 Clojure Problems – 24: Draw N Different Random Numbers From The Set 1...M

Example:

(deftest p24-lotto
  (let [draw (lotto 6 49)]
    (is (= 6 (count draw)))
    (is (>= 49 (apply max draw)))))

Solution

This is simple if you solved the previous problem. Just reuse random-select to select n numbers from the set 1...m which you pass in as the second argument.

Read more about this series.

No comments: