interesting, but since i dont know cr*p about C (or math), can u explain:
Perhaps you should read up a little on either C, or basic maths, first. Here is the code in Python, which you may find easier to read. Moan again, and I'll give it to you in FORTRAN.
from random import randrange
def one_ABX_run(num_trials, num_correct):
"""
Performs one simulated ABX run,
returns 0 if the trial was unsuccessful
1 if the trial was successful
success happens if we get more than
num_correct trials correct, out of num_trials
"""
c = 0
for i in range(num_trials):
if (randrange(2) == 1):
c += 1
return c >= num_correct
def calculate_pval(num_trials, num_correct, num_sims):
"""
Estimates the probability that you will be successful
by chance in an ABX test where you are required to get
num_correct correct guesses out of num_trials.
Estimation is by performing an ABX with the appropriate
parameters num_sims times.
"""
c = 0
for i in range(num_sims):
c += one_ABX_run(num_trials, num_correct)
return float(c) / num_sims
num_trials = 16
num_correct = 12
num_sims = 10000
print "pval =",calculate_pval(num_trials, num_correct, num_sims)