Well it depends, do you plan to show the ads as round robin structure?
If then all you need to do is to count each hit:
1 => ID1
2 => ID2
3 => ID2
4 => ID3
5 => ID3
6 => ID3
7 => ID1
8 => ID2
etc.
If this is a set structure that wont change, you can base which AD show when on math. But if you plan to change the ads, the percentage etc. It is better to handle the count by storage.
For example in a database, memcache etc. where you have a system that control which ad you showed last, and which to show next. Just keep in mind race conditions can happen in these systems, so store hits separately from the round robin, since it is possible that ID1 is shown two times on a row instead of one due to this.