concept rand - int in category clojure

appears as: rd-int
Clojure: The Essential Reference

This is an excerpt from Manning's book Clojure: The Essential Reference.

Once the local binding "x" has been established, the symbol can be used without re-evaluation of rand-int (which would then become problematic, since it would return different values for each invocation).

  • rand with no arguments: returns a pseudo random double number between 0.0 inclusive and 1.0 exclusive. rand-int requires at least one argument.
  • "n": is the bound for both functions and it must be of type double for rand and of type int for rand-int (negatives included).
  • The output is an integer for rand-int and a double for rand.

    (def random-vectors ; #1
      (repeatedly #(vec (drop (rand-int 10) (range 10)))))
    
    (first ; #2
      (drop-while
        #(>= 3 (count %))
        random-vectors))
    ;; [2 3 4 5 6 7 8 9]
    
    (reduce ; #3
      #(when (> (count %2) 3) (reduced %2))
      random-vectors)
    ;; [4 5 6 7 8 9]