[Tutor] What's the best way to model an unfair coin?

Richard D. Moores rdmoores at gmail.com
Sun Oct 24 19:13:57 CEST 2010

On Sun, Oct 24, 2010 at 09:22, Steven D'Aprano <steve at pearwood.info> wrote:
> Richard D. Moores wrote:
>> 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.
> Another approach you might take is to model the change as a normal
> distribution (bell curve probability) rather than uniform. This is probably
> more realistic. It would make most sense to have it symmetrical around zero,
> so you want a random number with a normal distribution, a mean of zero, and
> a standard deviation yet to be determined.
> To determine the standard deviation, use this rule of thumb: for a normal
> (bell) curve, approximately 68% of events are plus or minus one standard
> deviation from the mean; 95% are plus or minus two std deviations; and 99.7%
> are plus or minus three std deviations.
> So if you decide that 99.7% of the time the change in exchange rate should
> be less than 1.00, for example, that corresponds to a std deviation of
> 0.333.
> You then generate a normally-distributed value using the random module,
> round it to two decimal places to correspond to cents, and Bob's your uncle.

Ah, use random.normalvariate(mu, sigma), or random.gauss(mu, sigma)
where mu is the mean, sigma the standard deviation. Great idea. Thanks!

Bob IS my uncle! How'd you know? (First I'd heard that expression.
Interesting. <http://en.wikipedia.org/wiki/Bob%27s_your_uncle>)


More information about the Tutor mailing list