You should declare the variable "_i" as a global variable.
var _i=0; //global var
function on_space_event()
{
for(; _i < 15; _i += 1) {
if(random(1) < 0.5)
A();
else
B();
}
}
and if you want just one function to work each time you press the key, you don't need to use "for" loop. Something like this works:
var _i=0;
function on_space_event()
{
_i+=1;
if( _i>15)
{
return;
}
if(random(1) < 0.5)
A();
else
B();
}
}