Generating Random Numbers with Specified ProbabilitiesDate: 08/10/2003 at 16:54:06 From: Xeon Subject: Generating Random Numbers with Specified Probabilities Given an evenly distributed Pseudo Random Number (PRN) generator (with each generated outcome having the same probability), how can I generate outcomes with specified probabilities? For example, I want to generate these outcomes: A with 20% probability B with 15% probability C with 30% probability D with 15% probability E with 10% probability F with 10% probability As far as I know, the simplest approach is to use the PRN generated by the evenly PRN generator to index a single dimensional array with elements matched to the specifications. For the example above, this would mean the array would have 20 elements with the value of A, 15 elements with the value of B, 30 elements with the value of C, etc. The PRN generator should then be set to generate random values in the range of 1 to 100. The above approach is out of the question for my current needs. Are there any other ways to achieve the same effect? Date: 08/12/2003 at 04:11:32 From: Doctor Jacques Subject: Re: Generating Random Numbers with Specified Probabilities Hi Xeon, If you have only a "small" number of cases, as in your example, you should make a table of cumulative frequencies. For example, the probability of A should be 0.20, the probability of (A or B) should be 0.20 + 0.15 = 0.35, and so on. The nth row in the table gives the required probability of selecting an element less than or equal to the nth element (assuming a standard ordering of the elements). In your case, this gives the table: A 0.20 B 0.35 C 0.65 D 0.80 E 0.90 F 1.00 For example, the row C tells us that we should select (A or B or C) with probability 0.65. You can then use your PRNG to generate a random variable x between 0 and 1, and look in the table to find in which slot it falls, i.e. you find the first table row with a value greater than x. For example, if you produce x = 0.47, the first row greater than 0.47 is C (0.65), and so you will output C. If the table is somewhat large, you can find the correct row rather efficiently by using the binary search method (write back if you want to know more about this). Does this help? Write back if you'd like to talk about this some more, or if you have any other questions. - Doctor Jacques, The Math Forum http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/