rand-int - Clojure Standard Library
For a quick intro to this series of blog posts check out Clojure Standard Library - Intro. It includes a lot of useful info, including notes about presentation of examples and more.
This posts function:
rand-int
Quick Overview
Description
clojure.core/rand-int
returns a random integer between 0 and n (exclusive).
Example
(rand-int 10)
; => 2
(rand-int 30)
; => 26
How To Use
Parameters and Return Values
rand-int
is a 1-arity function – it accepts only one parameter that has no default value (it is mandatory).
(rand-int n)
- n is the max value (exclusive) and can be any number (e.g. integer, ratio, float).
Ex:
(rand-int 5000)
; => 3648
(rand-int 10.5)
; => 6
(rand-int 10/3)
; => 2
(rand-int 100/3)
; => 30