Skip to main content
gamedev.net
🔒 Locked

Probability calculation

Started by wasd 1 reply 900+ views
Original Post
wasd
wasd
I'm trying to calculate the amount of things that die from natural causes. At the moment, I've got this: For each thing, I do: if (Random number between 0 and 1) <= (Death probability) (Number to kill off) += 1 Which works fine and is exactly what I want, but I was wondering if there was a way to get the same kind of results with just a single calculation, e.g.: (Number to kill off) = (Random number) * (Death probability) * (Total number) The problem with the above is that it produces a lot lower numbers, and when there are a few things (between 1 and 100 say), you don't get any being killed off.
SiCrane
SiCrane
The sum of discrete random variables can be approximated by a gaussian distribution with the same mean and variance. Assuming each entity has the same probability of dying P with a total number T, then the mean would be P * T and the variance would be (1 - P) * P * T. Plug those values into your favorite gaussian random number generator.
alvaro
alvaro
What you are asking about is called binomial distribution.

A normal distribution is often a good approximation to the binomial distribution if you have enough events. If the probability of individual events is very small, a Poisson distribution is a better approximation.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.