rand returns a pseudorandom double. With no arguments, its result is at least 0.0 and less than 1.0, making it useful for probability checks and lightweight randomized behavior. section 5.10
Key properties:
- Accepts no arguments for the standard form; the listed additional arity accepts a double bound. section 5.10
- Returns a double rather than an integer. section 5.10
- Provides pseudorandom values through Java’s random-number facilities, which are suitable for many practical uses but not stronger randomness requirements. section 5.10
A/B choice
A probability check can select one of two outcomes: (defn A-B [prob A B] (if (< prob (rand)) A B)). Calling (A-B 0.5 new-feature control) gives each branch an approximately equal chance over many trials. section 5.10
Listing 5.6. → Random Numbers Generation
(rand ([]) ([n])) (rand-int [n])
Browse the compact function listing to compare rand’s arities with rand-int. section 5.10
