Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

random - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...