Readit News logoReadit News
donpdonp · 5 years ago
The method to get fair flips from an unfair coin is interesting and was recently on hackernews. say a coin is heads(H) 70% of the time. that means it must be tails(T) 30% of the time. If you flip it twice, and calculate the odds of each pair of flips (multiply the probabilities) - HH 49%, HT 21% TH 21% TT 9%. The middle two outcomes are equal probability, aka a fair coin. So ignore HH and TT flips and use HT and TH as Head and Tail of the 'fair' coin.
dragontamer · 5 years ago
Just note: you're throwing away 58% of your results! The original coin flip runs 230% the speed of your new RNG (that throws away so many results).

The Von Neuman method is a great way at demonstrating that removal of bias is possible, but not necessarily practical (especially at high bandwidth). In practice, you want to just cryptographic_hash(coin flips), which should maximize your entropy up to the entropy limit of 1/2 the hashsize (assuming you have a perfect cryptographic hash function).

A 512-bit perfect cryptographic hash can only support 256-bits of entropy, due to the birthday attack.

typicalset · 5 years ago
In the general case, you can compress a sequence of N biased coin flips with arithmetic coding. For a coin with known bias, this compression is (essentially) optimal and will therefore produce ~N*(Shannon information) unbiased bits.
ChrisLomont · 5 years ago
>assuming you have a perfect cryptographic hash function

Except there is no such thing (not in the sense you need it) - it too would be a perfect source of randomness, and you're just pushing the problem down the road.

As an example, NIST publication 800-90B recommends multiple randomness extractors, one of which is SHA. They recommend using twice the amount of entropy in as the entropy out to get random "enough" bits. Thus even SHA is not going to mix bits well enough as you want.

(The things called perfect hash functions in the literature map N items into N slots with no collisions, which is not what is needed here).

As a perhaps surprising counterexample to any simple solution, here [1] is a math paper with a proof that there can be no optimal algorithm that is best for all values of coin bias.

Here's [2] a cool walkthough on some of the ideas in theory that have been investigated.

[1] https://web.eecs.umich.edu/~qstout/abs/AnnProb84.html [2] http://www.eecs.harvard.edu/~michaelm/coinflipext.pdf

rini17 · 5 years ago
The entropy is -0.7log2(0.7)-0.3log2(0.3) = 0.88 .

The post is very confusing, in no case can deterministic hashing increase the entropy. And if it outputs only half of input entropy then it's only 8% more efficient than von neumann in this case.

btilly · 5 years ago
The Von Neumann method depends on coins being independent.

But the measured bias here is a 51% chance of getting what you started with. Which means that if you flip over and over again, there is a correlation between consecutive entries.

pmiller2 · 5 years ago
What says you can't reset the coin the same side up in between flips?
MrQuincle · 5 years ago
What about just after the unfair coin sequence toggling every even position?

HTHHTHHTTHHH

HHHTTTHHTTHT

Should be fair. Though there is order now when the coin was unfair.

Someone · 5 years ago
Fair, but only over time, and not truly random.

Only over time: this doesn’t help if you need _one_ fair flip.

Not random: for any 2 flips in sequence, you want a probability of ¼ to get two heads. This gets you either 70% × 30% or 30% × 70%, both of which are 0.21. That’s only 84% of the expected 0.25. In general, longer sequences of heads or tails are too rare with this method (e.g. for four flips: 70% × 30% × 70% × 30% is 0.0441; only 70.56% of the expected 0.0625. The probability of 6 consecutive heads or tails is less than 60% of what it should be, etc.)

EvgeniyZh · 5 years ago
Each individual flip is still unfair
jpcooper · 5 years ago
For those interested in games of chance, I've been playing around with Betfair's Exchange Hi Lo card game [1]. I came up with an algorithm to, given a game state, quickly compute the odds of all subsequent outcomes in polynomial time.

Based on this algorithm, I've been building a bot [2] to integrate with Betfair's games API to play automatically for me.

After finishing the first iteration, running it for a bit and losing a few Euros, I quickly realised that some of my assumptions as laid out in the README were wrong (I will be updating this soon). Namely, I wasn't accounting for Betfair's commission on winnings (silly me). I currently have an EU-based account, which has a 6.5 per cent commission on winnings. UK-based accounts have the minimum at 5 per cent. The commission has an effect on the cheapest profitable odds you can provide, which has an effect on whether people want to match bets at those odds.

With this in mind, it quickly becomes clear that any unmatched bets you see in the market are far from the maximum profitable odds. This makes sense, and competing based on odds becomes impossible at this point. I am led to believe that the only way to make money is by having a UK-based account plus getting the bets to the market first. I have a few ideas on how to do this.

If I can get the bets to match at odds that guarantee profit in the long-run assuming UK-based commission of 5 per cent, then I'm going to call it a day.

Regardless, I'm not expecting to make too much money from this. I have a lot of free time right now (looking for a job), so if anyone wants to get into anything else available on Betfair together, then please get in touch at the email on my Github through [2]. My discrete probability and programming are okay, but it would be great to have someone who could share their statistics knowledge.

[1] https://games.betfair.com/exchange-hi-lo/standard

[2] https://github.com/jpcooper/betfair-exchange-hi-lo-odds

chillydawg · 5 years ago
Heh.

I used to work on those products, way back in 2008 or so. Let me save you some time: you won't get any action at good odds. Or, if you do, it'll be a tiny amount.

Betfair run their own bots on those markets AND they get their bets into the market BEFORE the market opens to the public. Good luck anyway!

plafl · 5 years ago
And they will cannibalize your profits, up to 60%, if you start to make significant money. And they can kick you out anytime they want. It's all in the terms and conditions.
jpcooper · 5 years ago
Thanks for the heads up. It's good to get confirmation that that actually happens. I'd be surprised if it didn't. I'm not too far from implementing my final idea to get profitable bets in. If that (probably as you say) fails, then it was a fun learning experience.
ghgr · 5 years ago
Thanks for sharing (I recommend taking a look at his GitHub repo [2], where he nicely described the game and his approach).

Some time ago I had a similar project with BetFair soccer matches. I assumed that the number of goals from each team is given by a Poisson process. Then, I used the largest market (Win/Lose/Draw) to estimate this parameter. With this information I could estimate the "fair" odds of more exotics bets (like e.g. team A will score 3 goals more than team B), which were often mispriced, and then use the Kelly criterion to estimate how much to bet.

All in all a nice project, but... at the very end -just before deploying the bot- I realised that the BetFair Exchange is not open to Germans, so I wrote a blog post and open sourced the code. Still, a nice learning opportunity :-)

jpcooper · 5 years ago
Thanks. I would like to point out again that the code is out of date, and the margins displayed there are miscalculated due to not accounting for commission. The general spirit remains.

Did you backtest and show potential returns? Can you link to your model? Did you come across "Scoring dynamics across professional team sports: tempo, balance and predictability" [1]? They apply a Poisson model to team sports. I mentioned this paper to a company involved in betting who I interviewed with once, and they told me that they were doing something similar, but way more involved. It demotivated me somewhat regarding implementing it, making me wonder whether there really was any juice left to be squeezed from it.

[1] https://link.springer.com/article/10.1140/epjds29

aj7 · 5 years ago
Economic reasoning states that the vig will absolutely swamp any small edge you may discover.
rukuu001 · 5 years ago
These guys did it:

Walsh and Ranogajec took on the might of global gaming markets and managed to consistently win over three decades. Much like the most advanced hedge funds, which employ armies of PhDs to identify patterns in financial markets, Walsh and Ranogajec’s consortium, called the Bank Roll, created statistical models that allowed them to exploit mispricings in betting odds wherever they could be found

https://www.afr.com/opinion/david-walsh-s-wisdom-beats-the-o...

ximeng · 5 years ago
https://en.m.wikipedia.org/wiki/Vigorish For others who don’t know what vig is
jpcooper · 5 years ago
Someone has to provide a market. That person has to do it profitably. I am assuming that this is possible, otherwise it would not be possible to play the game. My reasoning could of course be off. Could you elaborate?
teej · 5 years ago
... you’re aware of the adage “the house always wins” right?
klinskyc · 5 years ago
Betfair is peer to peer, so the house just takes a rake (similar to poker). This means it is hypothetically possible for both you and the house to win.
jpcooper · 5 years ago
On Betfair the house is you. You determine the odds. Let's assume that cards are dealt randomly. If I know the exact probabilities of every outcome I bet on, and I always bet with odds which have a margin over those probabilities, then I win in the long run.
kirykl · 5 years ago
Using a bot is acceptable under their terms?
jpcooper · 5 years ago
Yes. They provide various APIs for this.
PragmaticPulp · 5 years ago
The key to breaking this potential advantage is to let someone other than the coin flipper call heads or tails while the coin is in the air.

That’s how I was taught to do it as a kid when we were playing for fun. I never really thought about the reasoning until now.

If you talk to people deep into the performance magic community, there are myths and legends of people who practice dice rolling to the point where they can influence the outcome of a dice roll. I suppose training for hours a day for years on end could have some such influence.

pschw · 5 years ago
It is definitely doable. _Scarne on Dice_ (1945) details a number of methods for controlling dice throws. And Steve Forte's "Gambling Protection Series" videos show what the moves look like in action.

Mind you, none of these moves will fly in a modern casino.

wool_gather · 5 years ago
Also the book "Gambling Scams" by Darwin Ortiz.

As I recall, the techniques generally involve not making normal "fair" free-tumbling rolls, but constraining the die movements somehow. Things like tossing them into a corner or making one of the pair spin flat, around only a vertical axis.

daveFNbuck · 5 years ago
That doesn't break the advantage, it just mitigates it. The advantage is just small enough that it doesn't matter much even before the mitigation. The caller could still look at the coin before it's flipped and have a slight edge in calling it.

It's not terribly hard to influence the outcome of a die roll. You can roll it end over end like a wheel so two of the faces remain on the sides and can't be the result.

tzs · 5 years ago
There was an episode of the old "Breaking Vegas" series [1] on the History Channel about such "dice dominators". This site seems to have the episode online [2].

[1] https://en.wikipedia.org/wiki/Breaking_Vegas

[2] https://www.goldentouchcraps.com/HistoryChannel.shtml

smcameron · 5 years ago
I remember when I was a kid, I had a book called "The Amateur Magician's Handbook", by Henry Hay, which described how lots of magic tricks and sleight of hand with cards, etc. were done, with detailed explanations and pictures. There was a section called "Heartbreakers", which contained tricks and techniques that were especially difficult to master. One of them involved predicting the outcome of a coin toss. The secret to it was that you just practice flipping and catching a coin to an extreme degree, aiming for consistency until you could replicate the action so precisely that the coin flipped the same number of times whenever you performed it. I practiced and practiced, but evidently not enough, because I could never do it. I found a bit of it online:

"18. Heads-or-tails. This I take on the good and sufficient word of Eddie Joseph. He explains how it is possible to flip a borrowed coin, and call heads or tails correctly every time.

"No trick to it -- just mechanical uniformity of action. It is obvious (when pointed out) that which face of the coin comes up depends simply on the number of revolutions the coin makes; and this depends on the weight of the coin, the height of the flip, and the force of the spin.

"By always using one denomination of coin, you fix the weight. The uniform flip of your right thumb comes with practice. To get a uniform height, pick some marked point on the wall, and practice until you can toss the coin just that high every time.

"You must also catch the coin on your left palm at exactly the same height each time -- your waist, naturally, is the easiest.

"Once you attain true uniformity, you will discover that the coin always comes down showing the same face that went up, or else always the opposite face. Experiment with different heights of toss, keeping track of the way the coin comes down. Never vary the force of your thumb flip because that is the hardest to judge.

"In performance, pick a mark such as a molding or picture frame on the wall of the room where you happen to be, make one trial toss to that height, and see whether the coin comes down the same as it went up, or opposite. Every time you toss to this mark afterward, the result should be identical.

godmode2019 · 5 years ago
I could do this by playing a lot of chess, the trick is the coin makes a certain sound if you do it right, if you do it wrong its not the same sound
thoughtstheseus · 5 years ago
With practice most people can dramatically influence the outcome of a coin flip. I’ve gotten to >80% accurate when I was practicing.
namenotrequired · 5 years ago
From the article:

> Diaconis himself has trained his thumb to flip a coin and make it come up heads 10 out of 10 times

TylerE · 5 years ago
10 out of 10 isn't really that impressive.

If his actual success rate is, say, 70 out 100 10/10 is easy enough to get by chance.

990 out of 1000 would be much more pressive.

thoughtstheseus · 5 years ago
Flip the coin the same number of times, catch consistently and get good at adjusting the catch. Use a large and heavy coin like a silver dollar. - former magic enthusiast.
tossthere · 5 years ago
Former Pokémon TCG enthusiast (circa 1999) here! Kids back then had the same approach, large and heavy coin, flip from a consistent height, consistent strength. Heads every time.

There were popular coins made specifically for Pokémon TCG then, and they happened to be large and thick and plastic and heavy, so the cheating was widespread.

I was one of the many kids who did this routinely. But there was one kid who took first place nearly every week, out of a field of 50+ entrants. “He must cheat the coin, AND be an amazing deck builder and card player on top of that”, I thought.

Then one week I was matched against him, winner goes to top 8.

Our decks were nearly identical, I could flip heads every time, I was a strong player. “50-50” I thought.

Turn one. Retreat Scyther, in Electabuzz, Thundershock. I flip my giant coin, and before it flattens, he picks it up and hands it back to me. “Flip it higher please.”

He must know I’m cheating. I assumed he must be cheating too though, every other kid is, and he wins this tournament every week!

Guilty, I flipped the coin fair this time, higher. Before it flattens he picks it up again, hands it back to me. “Higher please.”

I lost every coin flip that match. He won, went to the top 8, later won the tournament for the nth week in a row.

It wasn’t until adulthood that I realized how he was winning every tournament. In a field full of cheaters trying to flip heads every time, all he had to do was wait for the coin to enter that terminal spinning motion every coin does right before it flattens. Well practiced at this, if he sees that it’s about to flatten heads, he quickly grabs it and hands it back to you. “Higher please.” Repeat until the coin flattens tails.

His tactic was a silver bullet in a field full of flip cheaters. Nobody ever questioned his intentions when he grabbed the coin and asked for a higher flip.

mundo · 5 years ago
I can imagine that on a slow, lazy flip with a big coin, but is this realistic with what I think of as a "normal" flip, i.e. a US quarter, flipped rapidly end-over-end with the thumbnail, 2+ feet in the air? It's hard to believe that even decades of practice would get this reliable, and I don't think I've ever seen a stage magician rely on it in a routine.

For comparison, the other method (where the coin rotates about its vertical axis) is something you can learn to do tolerably well in a few minutes, and to do very well after a month or two at most. The motion of the coin will look perfect, and you can even get the "ding!" noise of a real flip. The only giveaway is the hand position; a real flip is done with the thumb under the coin, and this trick (for me, anyway) requires the thumb to be on top.

Source: taught myself to do this many years ago. I'm not a magician and have never used it to win money, I just use this to settle arguments between my kids.

throwaway2245 · 5 years ago
In this sense, I found the 51% surprising (surprisingly close to 50%).

If you have a very practiced, consistent flip, you can always get the same result.

jcheng · 5 years ago
The article notes that he got to 100% when intentionally biasing the flip, the 51% was for ordinary people doing ordinary coin flips (no attempt to bias).
unstatusthequo · 5 years ago
Appreciate the much-needed TLDR on this.
spiffytech · 5 years ago
What do you do to bias the outcome?
david927 · 5 years ago
Flip it with the right amount of force, like a juggler with bowling pins.
nojokes · 5 years ago
You catch it at the right moment. You learn to feel the right timing by practice.

Deleted Comment

hardmath123 · 5 years ago
See also: this short piece about detecting bias in coin tosses by listening to the “ping” they make when tossed. https://cs.stanford.edu/~kach/can-one-hear-the-fate-of-a-coi...
FpUser · 5 years ago
>"Diaconis didn't even own a computer. (He still doesn't. He says he got sick of adjusting to new operating systems and noted, after not using computers for several years, that "nothing bad happened to me. And I said, 'Well, I could either learn the current system or learn differential geometry. I think I'll learn differential geometry this year.'")"

Good for him. He made the right choice I think.

crazypython · 5 years ago
Sounds like he would enjoy GNU Emacs, which hasn't changed its interface in decades. Even the copy-paste shortcuts are the same.
_jal · 5 years ago
Having spent the majority of my days typing at various applications for the last 30 years, I have developed a great appreciation for UI longevity.

I'm a vi person by muscle-memory, and the stability there means I've learned a thing or two about it. But I've used emacs enough that I'm comfortable there, too, at least to a point.

Don't get me wrong, I love playing with new toys. But I also love not having to think about my tools - I'd rather think about what I'm building.

simonh · 5 years ago
The same is true of Notepad. It’s not really the point.

Dead Comment

kazinator · 5 years ago
Half-assed tosses of a flat object can obviously be biased. We can predictably flip an object to the other side with a light toss, not to mention flip a pancake.

If you flip a coin through the air so that it rapidly rotates (say more than 15-20 times) before being caught, that seems like it would erase the bias.

If there isn't decent spin, then "all bets are off" (quite literally).

As a matter of procedure, there should be a rule: the coin tosser must place the coin onto index finger, which is coiled around the thumb, such that just the edge of the coin is struck from below by the thumbnail, when the thumb is flicked, sending the coin upward in rapid rotation. There should be additional rules that the coin should attain a height of at least one head height above the top of the tosser's head, or something of the sort.

10000truths · 5 years ago
Better yet, just bounce the coin off of two surfaces before it lands. Makes it almost completely unpredictable.