3 ms·
To add to this: (one of) the correct solution(s) is R * 10 / 256 + 1 EDIT: I am wrong, this still has bias.
by demindiro 4y ago
To add to this: (one of) the correct solution(s) is
R * 10 / 256 + 1
EDIT: I am wrong, this still has bias.
- Spivak 4y agoYeah, an easy solution to all these things is “find a uniformly random source that outputs in a range larger but close to what you want and then try again if it’s outside your range. And indeed this is how Python does it https://github.com/python/cpython/blob/e37ac5fbb6de593521cf218aa05bc58a45c5a7c9/Lib/random.py#L238 https://github.com/python/cpython/blob/e37ac5fbb6de593521cf2... https://github.com/python/cpython/blob/e37ac5fbb6de593521cf218aa05bc58a45c5a7c9/Lib/random.py#L248 https://github.com/python/cpython/blob/e37ac5fbb6de593521cf2...