avid Posted November 15, 2017 Share Posted November 15, 2017 (edited) 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, 2017 by avid Quote Link to comment Share on other sites More sharing options...
Team Cape Posted November 15, 2017 Share Posted November 15, 2017 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 Quote Link to comment Share on other sites More sharing options...
Apaec Posted November 15, 2017 Share Posted November 15, 2017 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 1 Quote Link to comment Share on other sites More sharing options...
Alek Posted November 15, 2017 Share Posted November 15, 2017 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; } 1 Quote Link to comment Share on other sites More sharing options...