1.3.0 permalink Arrow_down_16x16
  • (rand)
  • (rand n)
Returns a random floating point number between 0 (inclusive) and
n (default 1) (exclusive).

2 Examples top

  • ;; Test `rand` never returns `n`:
    user=> (some (partial <= 10) (take 100000 (repeatedly (fn [] (int (rand 10))))))
    nil
    
  • user=> (rand)
    0.17469201779243182
    
    user=> (rand 100)
    49.542391492950834
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:4317 top

(defn rand
  "Returns a random floating point number between 0 (inclusive) and
  n (default 1) (exclusive)."
  {:added "1.0"
   :static true}
  ([] (. Math (random)))
  ([n] (* n (rand))))
Vars in clojure.core/rand:
Used in 0 other vars

Comments top

No comments for rand. Log in to add a comment.