int random(); /* random(N) returns random number between 0 and (N-1) */ int f(); /* f(r) is an arbitrary binary function that returns 1 only for a single value of r, for all other values of r it returns 0 */ main() { int i, r, answer = -1; r = random(N); for(i = 0; i < N; i++) { if (f(r) == 1) answer = r; r = random(N); } print(answer); }
Figure 2: Classical probabilistic program.