September 23rd, 2013, 04:31 PM
Question / Design approach for meeting distribution curve
Newbie poster here. I'm working on a project in C#, and I'm curious about your ideas for how to approach something.
This application is going to generate a random list of X number of Things. Each Thing is of a certain Type. The Types need to follow a particular distribution curve. For example:
Type A 5%
Type B 10%
Type C 50%
Type D 35%
So, the idea is, if I choose to generate 100 things, I would get 5 of Type A, 10 of Type B, 50 of Type C, and 35 of Type D. This is a very simple example, of course. In reality there are many more types with various frequencies.
What approach would you take to something like this? The main approach I was taking is as follows:
1. Treat the frequencies as integer values
2. Sum the total of the frequencies
3. Generate a random number between 1 and the total.
4. Loop through the Things, increasing a counter by the frequency of that thing.
5. If the random number is in the current range, then select that thing.
Thoughts on this approach?
In this method, will the results sets over time approximate the ideal distribution? Probability was never my strong point. If I wanted a little MORE variability in the distribution, I wonder how I could introduce that?
Thoughts greatly appreciated.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!