随机数

基本类型 / 数字 / 整型

(def rand1 (rand-int 3))
;; rand1 是 0、1 或 2,但绝不会是 3

(def rand2 (rand-nth [1 2 3]))
;; rand2 is 1, 2 or 3

;; 每次运行的值都不同,所以检查范围,而不是输出
(println "rand1 in #{0 1 2} is" (contains? #{0 1 2} rand1))
(println "rand2 in #{1 2 3} is" (contains? #{1 2 3} rand2))

;; 洗牌后的牌组保留每个元素,只改变顺序
(println "shuffle keeps the items is" (= #{1 2 3 4 5} (set (shuffle
                          (range 1 6)))))