title: Re-bind a Random Number Generator in Clojure
body: <p>I've got a function in Clojure which generates random numbers via <code>rand</code>:</p>
  
  <p><code>core.clj</code>:</p>
  
  <pre><code>(ns my-lib.core)
  
  (def my-rand rand)
  
  (defn my-fn []
    (take 3 (repeatedly my-rand)))
  </code></pre>
  
  <p>I'd like to test it, but it's hard since I don't know what to expect. Is there a way that I could re-bind <code>core/my-rand</code> such that it makes testing easier? Something like this:</p>
  
  <p><code>core_test.clj</code>:</p>
  
  <pre><code>(ns my-lib.core-test
    (:require [clojure.test :refer :all]
              [my-lib.core as core]))
  
  ; i'd like to re-bind the my-rand function here to make testing easier, but this doesn't work
  (def core/my-rand (constantly 1))
  
  (deftest my-fn
    (is (= (core/my-fn) '(1 1 1))))
  </code></pre>
  
  <p>Alternatively, is there a more idiomatic way of doing this?</p>