Catch ArrayIndexOutOfBoundsExceptions in random.clj
This commit is contained in:
parent
1e98e2916d
commit
66e33cdcf9
@ -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))))))
|
||||
|
Loading…
Reference in New Issue
Block a user