I have a doubt whether the uniformly distributed random generator is the most appropriate to use for simulating biased coin toss.
https://stackoverflow.com/questions/477237/how-do-i-simulate-flip-of-biased-coin-in-python
Let's say a chance of Democrat winning in a state is 0.6. Ok, so I thought at first it makes sense to use uniform..., in infinite number of trials, in 60% occasions the value will be below 0.6 (democrat winning).
However I was also wondering, should I use normal distribution instead?
So let's assign the value (x) = 0 for democrat, and value 1 for republican. In the chart, we can draw a bar whose height is 0.6 on x(0), and another bar 0.4 on x(1).
That makes the expected value (mu) = 0x0.6 + 0x0.4 = 0.4 The std deviation would be: square root of pow(0 - 0.4,2)*0.6 + pow(1-0.4,2)*0.4 = sort(24/100) = 0.49
Now, I execute random.gauss on python:
import random
random.gauss(0.4, 0.49)
I got: 0.9193140340408493
What do I make of that value? Should I interpret it as a win for Republican (under the rule: anything to the right of mean value goes to republican, the rest to democrat) ?
If that's not true, please help me pointing out the flaw in my reasoning, and a pointer to a topic in stats book to fix that.
Thanks in advance, Raka
ADDITION: background: I want to implement spinner similar to the one I see in NYT site: http://www.nytimes.com/newsgraphics/2014/senate-model/ .
The reason I was wondering if we should use normal random is because when I saw the source code of that page, it also uses normal random. Here's a snippet of the source code from that page (it's the click event handler; function named 'click'):
// Compute the national bias.
var nationalErrorScale = data.parameters.nationalErrorScale,
nationalBias = normalRandom() * nationalErrorScale,
localErrorScale = Math.sqrt(1 - nationalErrorScale * nationalErrorScale);
// For each race,
race.each(function(race) {
// Pick one of the potential matchups based on probabilities of each.
var matchup = race.matchups[bisectCumulative(race.matchups, Math.random())];
// Compute the local bias.
var localBias = normalRandom() * localErrorScale;
race.spinnerResult = matchup.mean + matchup.scale * (localBias + nationalBias) > 0 ? "dem" : "rep";
});