I want to get first N (for example 100) unique random floats. Here is what I have.
(defn rand-flt [max-flt] (format "%.2f" (rand max-flt))) (defn gen-rand-flts [max-flt] (lazy-seq (cons (rand-flt max-flt) (gen-rand-flts max-flt)))) (defn get-n-floats [max-float, how-many] (let [tf-fun (fn [] (take how-many (gen-rand-flts max-float)))] (loop [sof (set (tf-fun))] (if (> (count sof) (dec how-many)) (take how-many sof) (recur (set (concat sof (tf-fun)))))))) (get-n-floats 100.0 10) This works but I feel that should be more idiomatic solution for get-n- floats. I have tried take-while, some, even read about delay/force but couldn't come up with a shorter alternative; main problem is realizing lazy seq. Any suggestions? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en