### DB Fuller

commented on a video on YouTube.I chose k in three different ways with three different results (value in parenthesis is the 95% confidence interval half width):

-- Choose k and use it for all matches in all replications: result is 55.56% (±0.01%)

-- Choose k and use it for all matches of a single replication: result is 64.34% (±1.47%)

-- Choose k every time the game is played (a match): result is 66.67% (±0.01%)

The last result matches +Joshua Mcateer 's simulation. Although I avoided picking explicit limits as he did and other posters complained. (There are implicit limits in the Java language, but they are very large and I digress...)

My question is: I felt the results shouldn't be dependent on how often I choose k at all. Is there a reason this happened? Code mistake? Poor number generator? Interesting Math phenomenon +Numberphile can explain?

##### Code #####

import java.util.Random;

public class Main {

public static void main(String[] args) {

final int n = 1000000, replicN = 100;

double a, b, k;

long seed = 0;

Random r;

int win;

double[] resultArray = new double[replicN];

double avg, var, halfIntConf;

final String format = "%.2f";

//

// k = (new Random(1l)).nextGaussian(); //Choose k and use it for all replications: result is 55.56% (±0.01%)

for (int replic = 0; replic < resultArray.length; replic++) {

r = new Random(++seed);

win = 0;

// k = r.nextGaussian(); //Choose k and use it for this replication: result is 64.34% (±1.47%)

for (int i = 0; i < n; i++) {

k = r.nextGaussian(); //Choose k every time: result is 66.67% (±0.01%)

a = r.nextGaussian();

b = r.nextGaussian();

if ((a < k && a < b) || (a > k && a > b)) {

win++;

}

}

resultArray[replic] = ((double) win) / n * 100;

}

avg = 0;

for (double d : resultArray) {

avg += d;

}

avg /= replicN;

var = 0;

for (double d : resultArray) {

var += ((d - avg) * (d - avg));

}

var /= replicN;

halfIntConf = 1.96 * Math.sqrt(var / replicN);

//

System.out.println(

"Win percentage = " + String.format(format, avg) + "% " +

"(±" + String.format(format, halfIntConf) + "%)");

}

}