Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java normal distribution

I'm trying to simulate the arrival of fans to a stadium. The system itself, I believe it won't be a problem, but, the arrival of the fans follows a normal distribution.

My problem is:

I have a certain time for the arrival like 100 minutes and 1000 fans, and I need to generate arrivals of Fans at a time following that distribution like -> fan x arrived at 25 minutes, fan y arrived at 54 minutes, and so on.

How can I generate these random numbers following a normal distribution?

I'm doing this in Java and found the nextGaussian() method in the Random class, but I'm not sure how to use this in my situation.

Can someone please enlighten me?

like image 994
Henrique Gonçalves Avatar asked May 15 '11 23:05

Henrique Gonçalves


People also ask

How do you generate a random number from a normal distribution in Java?

double r = generator. nextDouble(); To generate a random number from a normal distribution, use "nextGaussian". This message takes no parameters and returns a random number from a normal distribution with mean 0 and standard deviation 1.

What is Java Gaussian?

Description. The nextGaussian() method is used to get the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Is rand () normally distributed?

You can use the RAND() function to establish probability and create a random variable with normal distribution.


2 Answers

nextGaussian() will draw samples from a normal distribution with mean 0 and std-deviation 1, so if you want mean 1 hour and std-deviation 15 minutes you'll need to call it as nextGaussian()*15+60.

From the docs for Random.nextGaussian():

Returns:
the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence

like image 190
ratchet freak Avatar answered Oct 30 '22 08:10

ratchet freak


I suggest you to use apache math: http://commons.apache.org/math/ , look here for more information: http://commons.apache.org/math/userguide/stat.html

like image 27
Pih Avatar answered Oct 30 '22 08:10

Pih