I want to be able to generate repeatable numbers using rand in Clojure. (Specifically, I want results of calls to rand-nth or Incanter\'s sample
rand
rand-nth
sample
Probably not the cleanest way, but you can make it work by redefining clojure.core/rand:
clojure.core/rand
(ns clojure.core) (def r (java.util.Random. 1)) (defn rand ([] (.nextDouble r)) ([n] (.nextInt r n))) (take 10 (repeatedly #(rand-int 10)))
This produces (5 8 7 3 4 4 4 6 8 8) every time I run it.