Results 1 to 5 of 5
  1. #1
    bondage is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default 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.

    normal distribution random number algorithm-picture1.jpg

    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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    bondage is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default 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

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,570
    Blog Entries
    7
    Rep Power
    21

    Default Re: normal distribution random number algorithm

    Quote Originally Posted by bondage View Post
    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:

    Java 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
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default 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.

Similar Threads

  1. Algorithm for filling random polygons
    By theraccoon in forum Java 2D
    Replies: 3
    Last Post: 05-18-2011, 06:35 PM
  2. Random Number Algorithm
    By javauserjava in forum New To Java
    Replies: 5
    Last Post: 04-06-2011, 12:32 AM
  3. Random number help
    By jgonzalez14 in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 09:13 AM
  4. Random number
    By jithan in forum Advanced Java
    Replies: 1
    Last Post: 06-13-2008, 01:42 PM
  5. Generate a random number
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •