If rand ≤ P then
Else
End If
Algorithm 1: Pseudocode of the first stage.