Use 1-5 random generator to generate 1-7 random number
Hint: How to do it with bit level
Roll the dice twice: and simply take XOR of result1 and ~result2, reject 7, keep 0~6.
explanation:
result1 is: 001 010 011 100 101
~result2 is: 110 101 100 011 010
You can see for each bit position the prob. of 1 bits is equal to prob. of 0 bits, and xor is also uniform distribution, thus result1 xor ~result2 is uniform distribution
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment