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
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to