I'm after a nice method to draw from a range of integers given known prior probabilities.
Say I wanted an 80% chance of drawing 1, a 15% chance of drawing 2, and a 5% chance of drawing 3...
I'm obviously thinking about this wrong, since neither
[~,I] = max([.80 .15 .05] .* rand(1,3))
nor
[~,I] = max([.80 .15 .05] + rand(1,3))
appears to achieve this...(rand samples from a uniform distribution)
Does anyone have a suggestion that will extend to any range of integers?
** Additional Comment **
I realise now for rational probabilities it's trivial just to create a vector comprised of these options proportionally (80% 1s, 15% 2s, and 5% 3s), and then just randperm the contents of the vector and choose the first element over and over...
This method is bad if the probabilities do not behave nicely...