point K must be selected out of possible points, K is a random variable with known probability distribution. I want to choose one of the points due to this distribution… how can I do that?
For example:
the points: 3 5 6 8
probability: 0.2 0.4 0.1 0.3
I want to select one of the points due to their probabilities.
I’ll not provide you with an exact function, however, with the code provided below it should be extremely easy to wrap it into a function.
The solution is based on Marks original comment, but uses
cumsum()to make the implementation a bit easier.