simulate dice with fair coin flip [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionGiven a fair coin (0/1), how do you simulate fair dice(0 to 5) Obvious answer I know is toss 3 times, treat each toss as a bit to produce (2^3 = 0 to 7) If result == 7, discard and repeat.
Well, theoretically worst case big-O of this is really bad (another question in itself, something to do with monte-carlo algos).开发者_JAVA百科 Lets keep this soln on shelf.
So now my question is, Is there/can there be n number of coin toss that can guarantee simulation of dice ? Of course if exists would like to know minimum number of tosses. :)
In absence of a number that is both divisible by three and 2^n, I couldnt think of any way to solve this. :(
精彩评论