November 15, 20178 yr Cruising the API and I see that grandom is deprecated. Does random offer a similar functionality considering standard deviation etc? Or is there some other function I should be using for similar results? EDIT: Perhaps I should use this: Edited November 15, 20178 yr by avid
November 15, 20178 yr 4 hours ago, avid said: Cruising the API and I see that grandom is deprecated. Does random offer a similar functionality considering standard deviation etc? Or is there some other function I should be using for similar results? EDIT: Perhaps I should use this: yes it will
November 15, 20178 yr I seem to remember it was deprecated because it wasn't functioning correctly; the API now only supports linear random. That being said, it's not too hard to come up with your own equivalent using https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextGaussian() Make sure to take into account far-edge generations though! Apa
November 15, 20178 yr I deprecated it because it doesn't create a normal distribution, it only creates the positive half of the bell curve. My official solution was/is the following: public static int gRandom(int mean, double stdDeviation) throws IllegalArgumentException { if (mean < 0) throw new IllegalArgumentException("Mean can't be lower than 0!"); double max = stdDeviation * 3; int result; do { result = Math.toIntExact(Math.round(random.nextGaussian() * stdDeviation + mean)); } while (Math.abs(result - mean) > max); return result; }
Create an account or sign in to comment