Gambler's fallacy
The gambler's fallacy is the logical fallacy of thinking that deviations from a longterm trend will be corrected in the short term.
Some examples:
 Someone who just lost ten times in a row playing the slot machines at a casino may think that a win is more likely on the next try.
 Someone playing roulette sees that red has come up repeatedly and so bets on black, thinking that result is "overdue".
The key feature of these examples is the randomness involved in the outcomes. In particular, both examples involve a sequence of independent trials in which the probabilities of future outcomes are not affected by previous outcomes.
The prototypical example of such a situation is the "welltossed" coin. As long as the coin rotates enough times before landing, the previous result ("heads" or "tails") will not affect the next one (i.e., the outcomes are independent of each other). Thus, just because the coin has landed on "heads" (say) multiple times in a row doesn't mean "tails" is more likely on the next toss.
Not always a fallacy
Note that such thinking is not always fallacious. When drawing playing cards from a well shuffled deck, for example, if the cards are not replaced between draws, then getting a long series of "nonaces", say, does make getting an ace more likely on the next draw. This is because drawing cards without replacement makes the trials dependent (not independent).This is largely how card counting works in Blackjack. (Note that when analyzing dependent events, conditional probabilities must be considered.)
Similarly, consider the following nongambling situations, which are not examples of the gambler's fallacy:
 A basketball player has made every one of his 10 freethrow attempts in the game. With two minutes to go, he has one last attempt. He might, in fact, be more likely to miss this time due to increasing fatigue throughout the game.
 A person living in an area that has been hit by significant earthquakes every five years, on the average, over the past 200 years has seen fifteen years go by since the last earthquake. She may reason that there is increased risk of another earthquake, perhaps even one of greater severity than usual, because earthquakes result from the sudden release of builtup stress in the Earth's crust. If there has not been an earthquake for a very long time, the stresses may have grown to a greater level than normal.
Analysis of the fallacious reasoning
Returning to the coin tossing example, someone engaging in the gambler's fallacy might be influenced by the entirely correct notion that getting more "heads" in a row is less likely than getting fewer in a row. However, this reasoning only applies when considering the full sequence of outcomes from the beginning. If you have already observed a sequence of outcomes and are anticipating future results, the "clock must be reset", so to speak, and what has already occurred should have no bearing on the future outcomes (although this is not to say our predictions need not take past occurrences into account—keep reading).
To be more specific, consider three scenarios in which gamblers are trying to win, say, $100:
 Gambler A predicts that a single coin toss will come up "heads".
 Gambler B predicts that 10 coin tosses in a row will come up "heads".
 Gambler C, after observing that nine tosses in a row have come up "heads", predicts that the tenth toss will come up "tails".
Clearly, Gambler A has made a pretty good bet. Assuming the coin is fair ("heads" and "tails" equally likely) — or even if the coin is not fair, assuming it's equally likely to be biased either way — he has a 1 in 2 chance (0.5 probability, sometimes paradoxically called "even odds") of winning the $100.
Similarly, Gambler B has made a pretty poor bet. He has a paltry 1 in 1,024 chance (0.5^{10} probability) of winning the money.
What about Gambler C? Well, Gambler C might have thought that predicting the tenth toss as "heads" after seeing nine "heads" in a row would be similar to Gambler B's prediction of ten "heads" in a row, but this reasoning is completely, er—wrongheaded.
If the coin is fair, Gambler C has exactly the same odds as Gambler A. However, if we allow for a biased coin, the nine "heads" in a row should probably be seen as evidence that the coin is in fact biased towards "heads", so the better bet might have been "heads" on the tenth toss! This illustrates how observed outcomes can be used to update our expectations (i.e., beliefs) of what will happen in a perfectly valid way, even though the previous outcomes do not actually influence future ones. (Note, though, that the conclusion arrived at was the opposite of that suggested by the gambler's fallacy.)
Related ideas
Similar ideas include the popular notion of the "law of averages" and the more subtle "regression toward the mean".
