Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: normal distribution random number algorithm

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

    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
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: normal distribution random number algorithm

    I'm not sure I understand exactly what you need, but it seems to involve a Normal distribution random number generator, in which case take a look at the nextGaussian() method of the Random class
    Random (Java Platform SE 6)

  3. The Following User Says Thank You to copeg For This Useful Post:

    bondage (January 16th, 2012)

  4. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: normal distribution random number algorithm

    hi,

    Would it be possible to have some assistance on the way forward to develop a random number using the von-neumann's acceptance -rejection method for the distribution in the image above? I am completley at a loss from where to start?

    thanks

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: normal distribution random number algorithm

    If you can get the algorithm, someone here can probably help you write the code.

  6. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: normal distribution random number algorithm

    One way to generate a random number for virtually any distribution is to use the cumulative distribution function of the distribution you want. You can generate uniformly distributed random numbers from y=[0,1], then solve the problem y=cdf(x) for x.

    Cumulative distribution function - Wikipedia, the free encyclopedia

  7. The Following User Says Thank You to helloworld922 For This Useful Post:

    bondage (January 16th, 2012)

  8. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: normal distribution random number algorithm

    Hi,

    the algorithm for the von-neumann acceptance-rejectiom method is as follows:
    1. generate a random number u between 0 and 180 (from the x-axis)

    2. generate a random number v between 0 and 7 such that 0<u<7 (since it must be greater than the maximum frequency distribution).

    3. if v<f(u), accept number u, else reject

    4. go back to step 1.

    The random number generated in step 1 must follow the probability of occurance as per the distribution in the image on the fist post, for example, the probability of mean service being 1 = 1/17, probability of mean service being 2 = 3/17 etc.

    thanks

Similar Threads

  1. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  2. How to returned random number to original number?
    By i4ba1 in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 19th, 2011, 04:35 AM
  3. random uniform distribution with probability assignment
    By blascobz in forum Object Oriented Programming
    Replies: 0
    Last Post: February 28th, 2011, 09:16 AM
  4. HELP. Random Number Between
    By Raymond Pittman in forum Java Theory & Questions
    Replies: 3
    Last Post: February 15th, 2011, 09:50 AM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM