algorithm - Generating numbers which follow Normal Distribution in Java -


i want generate numbers(randomly) such numbers follow normal distribution of given mean , variance. how can achieve this?

it better if can give in context of java. 1 might in these answers help: not precise. generate random numbers following normal distribution in c/c++

shamelessly googled , taken from: http://www.javapractices.com/topic/topicaction.do?id=62

the 'magic' happend inside random.nextgaussian()

import java.util.random;  /**   generate pseudo-random floating point values,   approximately gaussian (normal) distribution.   many physical measurements have approximately gaussian   distribution; provides way of simulating such values.  */ public final class randomgaussian {    public static void main(string... aargs){     randomgaussian gaussian = new randomgaussian();     double mean = 100.0f;      double variance = 5.0f;     (int idx = 1; idx <= 10; ++idx){       log("generated : " + gaussian.getgaussian(mean, variance));     }   }    private random frandom = new random();    private double getgaussian(double amean, double avariance){     return amean + frandom.nextgaussian() * avariance;   }    private static void log(object amsg){     system.out.println(string.valueof(amsg));   } }  

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -