Even within a university as famously offbeat as the Massachusetts Institute of Technology, Random Hall has a reputation for being a little quirky. According to campus legend, the students who first lived there in 1968 wanted to call the dorm “Random House” until the publishing house with that same name sent them a letter to object. The individual floors have names, too. One is called Destiny, a result of its cash-strapped inhabitants selling the naming rights on eBay; the winning bid was $36 from a man who wanted to name it after his daughter.

In 2005, another plan started to take shape in the corridors of Random Hall. James Harvey was nearing the completion of his mathematics degree and needed a project for his final semester. While searching for a topic, he became interested in lotteries.

He began analyzing well-known lottery games such as Powerball and MegaMillions, but soon became intrigued by Cash WinFall, a game that was introduced in 2004 and was unique to the state of Massachusetts. The rules were simple. Players would choose six numbers for each two-dollar ticket. If they matched all six in the draw, they won a jackpot of at least half a million dollars. If they matched some but not all the numbers, they won a smaller sum. The lottery designed the game so that $1.20 of every $2.00 would be paid out in prizes, with the rest being spent on local good causes.

In many ways, WinFall was like all the other lottery games. However, it had one important difference: Usually, when nobody wins the jackpot in a lottery, the prize rolls over to the next draw. If there’s no winning ticket next time, it rolls over again and continues to do so until somebody eventually matches all the numbers. The problem with rollovers is that winners—who are good publicity for a lottery—can be rare. And if no smiling faces and giant checks appear in the newspapers for a while, people might stop playing.

Massachusetts Lottery faced precisely that challenge in 2003, when its Mass Millions game went without a winner for an entire year. They decided that WinFall would avoid this awkward situation by limiting the jackpot. If the prize money rose to $2 million without a winner, the jackpot would “roll-down” and instead be split among the players who had matched three, four, or five numbers.

Before each draw, the lottery published its estimate for the jackpot, which was based on ticket sales from previous draws. When the estimated jackpot reached $2 million, players knew that the money would roll-down if nobody matched six numbers. People soon spotted that the odds of winning money were far better in a roll-down week than at other times, which meant ticket sales always surged before these draws.

As he studied the game, Harvey realized that it was easier to make money on WinFall than on other lotteries. In fact, the expected payoff was sometimes positive: When a roll-down happened, there was at least $2.30 waiting in prize money for every $2.00 ticket sold.

In February 2005, Harvey formed a betting group with some of his fellow MIT students. About 50 people chipped in for the first batch of tickets—raising $1,000 in total—and tripled their money when their numbers came up. Over the next few years, playing the lottery became a full-time job for Harvey. By 2010, he and a fellow team member incorporated the business. They named it Random Strategies Investments, LLC, after their old MIT accommodations.

Other syndicates got in on the action, too. One team consisted of biomedical researchers from Boston University. Another group was led by Gerald Selbee, a retired shop owner and former math student who had previously had success with a similar game elsewhere. In 2003, Selbee had noticed a loophole in a Michigan lottery game that also included roll-downs. Gathering a 32-person-strong betting group, Selbee spent two years bulk-buying tickets—and winning jackpots—before that lottery was discontinued in 2005. When Selbee’s syndicate heard about WinFall, they turned their attention to Massachusetts. There was a good reason for the influx of such betting teams: Cash WinFall had become the most profitable lottery in the United States.

During the summer of 2010, the WinFall jackpot again approached the roll-down limit. After a prize of $1.59 million went unclaimed on August 12, the lottery estimated that the jackpot for the next draw would be around $1.68 million. With a roll-down surely only two or three draws away, betting syndicates started to prepare. By the end of the month, they planned to have thousands more dollars in winnings.

But the roll-down didn’t arrive two draws, or even three draws, later. It came the following week, on August 16. For some reason, there had been a huge increase in ticket sales, enough to drive the total prize money past $2 million. This flood of sales triggered a premature roll-down.

The lottery officials were as surprised as anyone: They had never sold that many tickets when the estimated jackpot was so low. When WinFall was introduced, lottery officials had looked into the possibility of somebody deliberately nudging the draw into a roll-down by buying up a large number of tickets. Aware that ticket sales depended on the estimated jackpot—and potential roll-downs—the lottery didn’t want to get caught underestimating the prize money.

They calculated that a player who used stores’ automated lottery machines, which churned out tickets with arbitrary numbers, would be able to place 100 bets per minute. If the jackpot stood at less than $1.7 million, the player would need to buy over 500,000 tickets to push it above the $2 million limit. Because this would take well over 80 hours, the lottery didn’t think anyone would be able to tip the total over $2 million unless the jackpot was already above $1.7 million.

The MIT group thought otherwise. When James Harvey first started looking at the lottery in 2005, he’d made a trip to the town of Braintree, where the lottery offices were based. He wanted to get hold of a copy of the guidelines for the game, which would outline precisely how the prize money was distributed. At the time, nobody could help him. But in 2008, the lottery finally sent him the guidelines. The information was a boost for the MIT group, which until then had been relying on their own calculations.

Looking at past draws, the group found that if the jackpot failed to top $1.6 million, the estimate for the next prize was almost always below the crucial value of $2 million. Pushing the draw over the limit on August 16 had been the result of extensive planning. As well as waiting for an appropriate jackpot size—one close to but below $1.6 million—the MIT group had to fill out around 700,000 betting slips, all by hand. “It took us about a year to ramp up to it,” Harvey later said. The effort paid off: It’s been estimated that they made around $700,000 that week.

Unfortunately, the profits did not continue for much longer. Within a year, The Boston Globe had published a story about the loophole in WinFall and the betting syndicates that had profited from it. In the summer of 2011, Gregory Sullivan, Massachusetts’s Inspector General, compiled a detailed report on the matter. Sullivan pointed out that the actions of the MIT group and others were entirely legal, and he concluded that “no one’s odds of having a winning ticket were affected by high-volume betting.” Still, it was clear that some people were making a lot of money from WinFall, and the game was gradually phased out.

Even if WinFall hadn’t been canceled, the Boston University syndicate told the inspector general that the game wouldn’t have remained profitable for betting teams. More people were buying tickets in roll-down weeks, so the prizes were split into smaller and smaller chunks. As the risk of losing money increased, the potential rewards were shrinking. In such a competitive environment, it was crucial to obtain an edge over other teams. The MIT group did this by understanding the game better than many of their competitors: They knew the probabilities and the payoffs and exactly how much advantage they held.

Betting success is not just limited by competition, however. There is also the not-so-small matter of logistics. Gerald Selbee pointed out that if a group wanted to maximize their profits during a roll-down week, they needed to buy 312,000 betting slips, but the process of buying so many tickets was not always straightforward. The ticket machines would jam in humid weather and run slowly when low on ink. On one occasion, a power outage got in the way of the MIT group’s preparations. And some stores would refuse to serve teams altogether.

There was also the question of how to store and organize all the tickets they bought. Syndicates had to keep millions of losing tickets in boxes to show to tax auditors. Moreover, it was a headache to find the winning slips. Selbee claims to have won around $8 million since he started tackling lotteries in 2003. But after a draw, he and his wife would have to work for 10 hours a day examining their collection of tickets to identify the profitable ones.

Syndicates have long used the tactic of buying up large combinations of numbers—a method known as a “brute force attack”—to beat lotteries. Simple brute force approaches do not require many calculations to pull off. The only real obstacle is buying enough tickets. It’s more a question of manpower than mathematics, and this reduces the exclusivity of the methods. Whereas clever roulette players have only to outwit the casino, lottery syndicates often have to compete with other teams attempting to win the same jackpot.

Despite the ongoing competition, some betting syndicates have managed to repeatedly—and legally—turn a profit. Some of them have become so dependably successful, in fact, that they even have investors and file tax returns. What were once sporadic efforts to beat the system have grown into an entire industry.

This article has been adapted from Adam Kucharski's book, The Perfect Bet: How Science and Math Are Taking the Luck Out of Gambling.