Lets you first define a function that updates a random index in a vector with a new value. Note that the original vector does not change; instead, a new vector is returned (with the updated value):
(defn f [xs] (let [r (java.util.Random.) i (.nextInt r (count xs)) b (.nextBoolean r)] (assoc xs i ((if b inc dec) (xs i)))))
This function selects the index, and then either increases or decreases the value in this index by 1. You, of course, must change this function to suit your needs.
Then just write this function with you as many times as you want to run the simulation:
user=> ((apply comp (repeat 1000 f)) [0 0 0 0 0 0 0]) [7 -4 7 6 10 0 -6]
Jonas
source share