From 66e33cdcf9a6136a09f4510f96eefbe54fc27030 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sun, 1 Apr 2018 10:05:22 -0400 Subject: [PATCH] Catch ArrayIndexOutOfBoundsExceptions in random.clj --- src_clj/sketchbook/random.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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))))))