vectorized p_random calculation