Hacker News new | ask | show | jobs
by vikingerik 977 days ago
Also interestingly, this extends beyond a two-sided coin, to any number of possible results, like a die with N sides.

To get a fair result from a biased dN: Roll it N times. If you don't get all N distinct results, restart. If you do, then the first of those is your final result.

1 comments

Also-related are all the problems like "simulate an 11-sided die with a 6-sided die", where the solution involves identifying certain rolls that should trigger a retry. [0]

In both cases it has to do with shaping the combination of multiple rolls using some knowledge of outcome-symmetries and overlaps.

____

[0] In this particular case, that's something like: Roll the die twice to get rolls A and B; map those a number X in the range range [1,36] using x=(((A-1)*6)+B); if X<=33 then return (x%11)+1 which will be equally likely in the range [1,11]; if X>33 then start over.