Asymptotic Formula For Counting In Deterministic And Random Dynamical Systems