A pseudo-random number generator produces useful random-looking values efficiently, while remaining algorithmic rather than perfectly random. Clojure exposes this capability through rand and rand-int, backed by Java generation facilities. section 5.10
Clojure's two functions differ in input and output:
- rand with no arguments returns a double x where 0.0 ≤ x < 1.0; an optional bound must be a double. section 5.10
- rand-int requires an integer bound and returns an integer from zero to that bound; negative bounds are allowed. section 5.10
A/B rollout
Use rand to select roughly half of requests for a feature: (if (< 0.5 (rand)) new-feature old-feature). For an integer choice, (rand-int -10) can produce a value such as -5. section 5.10
Listing 5.6. → Random Numbers Generation
(rand ([]) ([n])) (rand-int [n])
Browse the concise function signatures for rand and rand-int. section 5.10









