Return a random element of the (sequential) collection. Will have the same performance characteristics as nth for the given collection.
user=> (def food [:ice-cream :steak :apple]) #'user/food user=> (rand-nth food) :apple user=> (rand-nth food) :ice-cream
user=> (def food [:ice-cream :steak :apple]) #'user/food user=> (rand-nth food) :ice-cream user=> (rand-nth food) :ice-cream
user=> (rand-nth []) IndexOutOfBoundsException clojure.lang.PersistentVector.arrayFor (PersistentVector.java:158) user=> (let [xs []] (when (not (empty? xs)) (rand-nth xs))) nil
Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive).
Return a random permutation of coll
Returns the value at the index. get returns nil if index out of bounds, nth throws an exception un...
rand-nth