Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a fixed solution space defined by a minimum and maximum float which has no divisible slice.

You then have 0..N Gaussian distribution probability sets which I need to combine.

In the end I neeed

  1. Method to define probability set with a numeric range (not sliceable) and 0..N Gaussian functions
  2. A function which can generate a random number in the range as defined by the calculated probabilities.

Also I know it is possible that some combinations will generate a zero solution space.

Now I'm thinking the way to do it is take the normalised probability density functions and multiply them to get a new space then normalising the result. I just can't seem to break it down into algorithmic form.

Any ideas?

share|improve this question
You would probably be better off asking this at – bummzack Aug 15 '10 at 10:59
I thought about that, but I'm mostly concerned with how to do it algorithmically. A pure maths solution would help but not be the answer. – Kimau Aug 15 '10 at 11:05
Then maybe try It looks like a generic programming problem, I don't see the word "game" in your post anywhere (not that it's a requirement but that's a pretty good sign that you might want to look elsewhere) – Ricket Aug 15 '10 at 15:41
I need help with some terms, like no divible slice, zero solution space, normalized probility density. – Jonathan Fischoff Aug 15 '10 at 16:20
Hmm. the top hit for "divisible slice" on google is this question. Then a number of documents where "divisible" and "slice" occur next to each other, but are part of different sentences. You might want to explain that one, as it's obviously not uniform usage. – drxzcl Aug 16 '10 at 7:45

First let's make sure I understood your question correctly:

  • You have a probability function that is expressed as a sum of N parametrized one-dimensional gaussians, each with different mean and standard deviation.
  • You want to generate stochastic variables according to this distribution.

Is this correct?

If this is the case, I reccommend you use a variation of rejection sampling. The recipe is quite straightforward, but you might have to iterate a bit before you get an answer out of it. This is the basic outline.

  1. You generate a uniformly distributed random number in your desired interval, x.
  2. You calculate the value of your probability distribution, p(x)
  3. You generate another uniformly distributed random number between 0 and 1, q
  4. If q < p(x), return x
  5. If not, start from step 1.

No matter how large the temptation, do not re-use q for different iterations.

share|improve this answer
I cannot use this method because as I stated a floating range is non-divisible (not sliceable). So sampling is impossible. I already use this method for enumerations which are possible to sample. Also I've taken advice and moved this question to Math Stack… – Kimau Aug 21 '10 at 8:13
Ok, let's move there. – drxzcl Aug 21 '10 at 15:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.