◐ Shell
clean mode source ↗

Non-uniform random floats (_randommodule.c) by amrali-eg · Pull Request #31606 · python/cpython

The method Python uses is the same as was shipped with the original Mersenne Twister code, so is a de facto industry standard. We're not going to change it without superb reason, and so far here there's no reason at all 😉. Note that all the buildbot tests failed here: that's because you changed random()'s output. That's not something that can be done either without superb reason.

I have no idea what you did, and since your links don't work as intended for me, apparently no way to find out. Here's a simple test of the distribution of the last 3 bits you can run yourself:

from random import random
counters = [0] * 8
T53 = 2.0 ** 53
for x in range(1000000):
    r = random()
    i = int(r * T53)
    assert i / T53 == r
    counters[i & 7] += 1
for c in counters:
    print(c)

Here's output from one run:

124729
124854
125701
125369
124791
124641
124833
125082

By eyeball it looks fine.

Please move this to bugs.python.org if you want to pursue it. That's the place for extended discussions, not here. And attach the actual code you used to the issue report.

About your other code, there may be some niche demand for the possibility of generating random floats that can be less than 1/2**53, but, again, we cannot change the output of random.random() without superb reason. People expect to be able to seed the generator to a known value, and get exactly the same results across Python releases.