The actual counter is updated every 5 minutes. The script on the apple site downloads this number and the number 5 minutes before, and determines a probable number of songs sold.
By analyzing the data of the last 500K sales or so, it should be possible to write a program that quite precisely determines when the 500 millionth song is sold, based on patterns in previous activity. Id est, writing an exponential formula that in addition to taking the previous number into account, bases the calculation on every difference in growth since the counter started.
Of course - the buying process would also have to be automated to make the program usable, because of the short time intervals. And a cheater would probably have to buy a few thousand songs to be sure to win.
It also depends on how the store database handles transactions. If entirely procedural and queue-based, the chance of winning by buying a large amount of songs at a given time is greater. Else, the probability could be only a few percent even if the time is determined precisely.