[Tutor] What's the best way to model an unfair coin?
Richard D. Moores
rdmoores at gmail.com
Sun Oct 24 15:33:09 CEST 2010
On Sun, Oct 24, 2010 at 05:17, Steven D'Aprano <steve at pearwood.info> wrote:
> Let probability of heads = p, where 0 <= p <= 1
> Then probability of tails = 1-p.
> if random.random() <= p: print("got heads")
> else: print("got tails")
My thanks to Evert, Steven, and Alan. I should have thought of that solution.
Actually, I used the unfair coin model as the simplest example of the
kind of thing I want to do -- which is to model the USD->Yen exchange
rate. I want the next quote to vary in a controlled random way, by
assigning probabilities to various possible changes in the rate. See
<http://tutoree7.pastebin.com/mm7q47cR>. So I assign probability 1/40
to a change of plus or minus .05; 3/40 to .04; 5/40 to .03, etc.
An analogy to this would be an unfair 6-sided die, with each side
assigned probabilities slightly differing from 1/6 (but totaling 1, of
course). I can't see off-hand how to apply the Evert-Steven-Alan
solution to these, but is it possible? I'd just like a yes or no -- if
yes, I'd like to try to work it out myself.
More information about the Tutor