1 Attachment(s)

normal distribution random number algorithm

Hi,

I need to develop a method that basically returns a random number based on specific parameters as defined below.

The context is that this method wil go in a wider implementation of a discrete-even simulation model that reflect a specific traffic system.

Basically, the input requires to be of type double. The output must be of type double as well. I have the graph below which is to be used to development of the algorithm to return a random number.

As shown in the image, service time changes as time passes. between 06.00am and 07.10 (70 mins), mean service time is 1. Between 07.10 and 7.35 (70 mins till 95 mins), mean service time is 3 etc. I would require that the random number returned displays this characteristics, i.e. as from time NOW = 0 (mins) to time now = 70 (mins), there is a mean service time of 1 etc.

Attachment 2052

I am not exactly sure how to go along and develop this. Does it make sense to develop an array with probabilities?

Any help would be appreciated.

Re: normal distribution random number algorithm

Have a look at the Random class, it has a nextGaussian() method that returns a N(0, 1) pseudo random number (mean == 0, standard deviation == 1); you can always adjust such a number r by transforming it to m+s*r where the mean == m and the standard deviation is s.

kind regards,

Jos

Re: normal distribution random number algorithm

Josah,

thanks for your reply. Do you by any chance know of any resources that can help in the implementation / pseudocode?

thanks

Re: normal distribution random number algorithm

Quote:

Originally Posted by

**bondage** Josah,

thanks for your reply. Do you by any chance know of any resources that can help in the implementation / pseudocode?

thanks

There is not much you have to do:

Code:

`// create a random number generator`

Random rand= new Random();

...

public double getRandom(double mean, double stddev) {

return stddev*rand.nextGaussian()+mean;

}

kind regards,

Jos

Re: normal distribution random number algorithm

Jos has addressed the question of generating numbers randomly such that they have a specified normal distribution as you mentioned in the title of your post.

However the graph you posted does **not** show a normal distribution. What it shows is the mean service time taking certain discrete values at different times. It looks like you need 6 actual service time distributions, one for each of the bars. Each one would have a mean being the height of the corresponding bar.

The problem is underspecified to the extent that the graph says nothing about the desired value of the standard deviation of actual service times at any time of day.

The distributions that have the mean values shown in the graph cannot be gaussian (normal) unless you are happy with allowing for arbitrarily large actual service times and, more worryingly, negative ones.