On optimal heuristic randomized semidecision procedures, with applications to proof complexity and cryptography