'How do I determine probability in python?
I am trying to translate a probability equation into python. the equation stated in the paper is a probability of capture = -.33+.15(predator length/prey length) predator length is 90 and prey length is 12 but grows by 0.2 every time step
I am using this equation to determine the probability of capture using a random number. if the random number is less than or equal to the probability of capture then the individual is captured if it's greater than or equal to it would survive to grow and move to the next time step. so how would I go about laying out this equation into code.
Solution 1:[1]
random() will output a float from 0.0 (inclusive) to 1.0 (exclusive). So if your probability x goes from 0.0 to 1.0 and for example is 0.33 (33%) just check if random.random() < x and then consider the "predator capture" event as true.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Attersson |
