diff --git a/src_clj/sketchbook/random.clj b/src_clj/sketchbook/random.clj index 182e9a4..6f5f1be 100644 --- a/src_clj/sketchbook/random.clj +++ b/src_clj/sketchbook/random.clj @@ -10,10 +10,16 @@ (defn random ([max] (random 0 max)) ([min max] - (+ (* (.nextFloat rng) (- max min)) min))) + (try + (+ (* (.nextFloat rng) (- max min)) min) + (catch ArrayIndexOutOfBoundsException e + (random min max))))) (defn random-normal ([] (random-normal 0 1)) ([mean dev] (let [distribution (NormalDistribution. rng (double mean) (double dev))] - (.sample distribution)))) + (try + (.sample distribution) + (catch ArrayIndexOutOfBoundsException e + (random-normal mean dev))))))