When it comes to casinos, it's no secret that the house always wins. And while roulette might be one of the most popular of the Vegas games, it's also got some of the worst odds. Unless you have an uncanny knowledge of physics, that is.

Back in the '70s, a mathematician called J. Doyne Farmer famously built a machine that allowed him to skew the odds of roulette so significantly in his favour that he's since been banned from all the casinos in Nevada. And now a colleague has just told the internet how it works.

Before we get started, let's make it very clear that we're not endorsing gambling (or using science to do anything illegal). But there's some pretty bad-ass physics and statistics to be learned here.

The new insight into the roulette-beating machine was revealed over on Quora this week, when someone asked the world wide web "What do physicists know that lets them win at casinos?"

The top-voted answer came from Richard Muller, a professor of physics at the University of California, Berkeley, who admitted that a colleague of his once built a device that allowed him to beat the roulette table.

As Muller explains:

"It worked as follows: to encourage people to bet at roulette, it has been traditional to allow bets to be made after the wheel is spun and the ball is flung, but only before it begins to drop. In that second or two, there is enough information to allow a measurement and computation that will, for example, double your odds of winning.

If the computation simply rules out half of the wheel as unlikely, then the odds jump up highly in your favour. Whereas before, your odds of winning might be 98:100 (so you lose), if you exclude half of the numbers, your odds become 196:100; you win big!

You don't have to predict the number where it will fall. You only have to increase your odds by 3 percent to go from losing on average to winning on average."

With that in mind, Muller explains that the machine worked by attaching a switch to the player's toes. The player would tap one switch each time the ball completed a full spin, and the other switch each time the wheel spun.

From that data, a small pocket computer could calculate the odds and let him know, via a tap on the leg, where he should place his bet. All in the small window of time before the ball stops spinning. 

Of course, to figure this out, he first had to calibrate his device using a real casino roulette wheel, which he did by buying his own wheel and testing it in his garage before hitting the tables.

"The casinos don't have the right to search you, so how can they guard against devices such as that?" writes Muller. "To do that, they have lobbied to make a law that they can exclude any person without cause. They choose to do that only when they see someone consistently beating the odds. They can't get their money back, but they can stop losing … Indeed, my friend (who was then a gradate student at Berkeley) was put on the list."

To be clear, Muller doesn't specify that he's talking about Farmer in his answer, but the story definitely matches up with Farmer's famous casino scam.

And for all the doubters out there, this isn't just a science urban legend. Back in 2012, researchers Michael Small from the University of Western Australia, and Chi Kong Tse from Hong Kong Polytechnic University, published a paper that showed for the first time in a peer-reviewed journal how this process works.

The team was able to demonstrate that simply knowing the rate at which the wheel and ball are spinning - before the ball starts bouncing and everything gets random - is enough to skew the odds.

In fact, by using a system similar to Farmer's where they recorded each time the ball or wheel passed a certain point, they showed that they could win on average 18 percent of the time - well above the negative 2.7 percent currently expected from a random bet. 

"Knowing the initial conditions allows you to beat the odds," said Small at the time. "In some cases you can beat them quite significantly."

The release of that publication actually prompted the first public response from Farmer about his machine, and he admitted that their technique was very similar to the one he'd used in his device - except that Small and Kong Tse had assumed that the main force slowing the ball down was friction with the rim, whereas he'd calculated that it was air resistance.

So does using physics to outsmart the house pay off? It can… until the casino figures out what you're up to and bans you for life, as was the case with Farmer, who definitely didn't get rich off his scheme. 

"He says he almost made enough money to pay for the roulette wheel he had purchased to perfect his instrument at home before going out 'into the field'," recalls Muller. Damn.