2 ms·
Yeah, 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
by Spivak 4y ago
Yeah, 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...