[Tutor] What's the best way to model an unfair coin?
Richard D. Moores
rdmoores at gmail.com
Sun Oct 24 13:32:43 CEST 2010
What's the best way to model an unfair coin?
This is one way to do it, I suppose: Create a list containing only
'H's and 'T's. If you want the coin to have the probability of a head
to be 6/11,
['H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'T', 'T', 'T']
is the list to use. Use random.choice on the list, for a 6/11 heads
probability.
See <http://tutoree7.pastebin.com/gxKYkYWW>.
That's the only way I can think of. But surely there's a better, more
general solution. What if the probability I want is an irrational
number, such as 1/e? Sure, I can calculate a fraction that's as close
to that irrational number as I want, but..
Am I missing something that's already there in Python 2.6 or 3.1 (the
2 I have)?
Dick Moores
More information about the Tutor
mailing list