for (i = 0; i < N; i++) {
s = rand(); r = rand();
if (r <= f(s)) n++;
}