but if they have a few clients... who pay different amount of money for different number of impression... how do they display their ads in random and yet have the probability % higher for seeing the ads for the company who paid more for more impression.
i would imagine they just keep track of how many times a certain customers ad has been displayed. once they have met thier obligation, that ad is removed from the table of possible ads to serve.
things could get much more complicated though if they have to serve x amount of adds for a customer within a certain time limit. also if they want to space x amount of impressions over a certain time span, like a week or month so they get steady traffic for a while, instead of a burst of traffic which stops when they have consumed thier impressions.
how 'random' they wanted it to be would also influence how they code it.
assuming the more complex situations like time limits, i suppose they might generate a lookup table, maybe regenerating it every few hours or whatever. that would allow them to control the rate of impressions for each ad without having to compute everythign too often, and would allow them to try to smooth the rate out.
when they generate the lookup table they can consider various factors like how many impressions need to be fulfilled for each customer, how much time they have left to fullfill it, taking into account how many ads they normally serve per minute etc...and use that to decide how many of each ad get placed into the lookup table.