I wanted to use it to select a random element in a collection (set,
vector or list) where I can define elements which should not be selected.
The function I now use is:
(defn select-random [collection & unselect]
"(select-random collection & unselect) selects a random element from
the specified 'collection'.
It will ignore any element which is specified in 'unselect'. If none
elements are specified in 'unselect',
then any element from the specified 'collection' may be chosen. "
( let [predicate #(contains? (set unselect) %1)]
(rand-nth (remove predicate collection))))
Eventually this can be optimized for better reading and/or performance.
It might be also a good idea to add some preconditions to it like
{pre: [(coll? collection)] }.