InigoSJ commented on pull request #15912:
URL: https://github.com/apache/beam/pull/15912#issuecomment-962264660
> Looking at #15753, the question to answer:
>
> Is `random.getrandbits(32)` equivalent to `random.randint(0, (1 << 32) -
1)`?
I have ran a quick test and the distribution is the same, hitting the same
low and high values:
```
def test_randoms(bits, M, epsilon = 0.05):
bit_d = collections.defaultdict(lambda: 0)
normal_d = collections.defaultdict(lambda: 0)
for _ in range(M):
bit_d[random.getrandbits(bits)] += 1
normal_d[random.randint(0, (1 << bits) - 1)] += 1
for key in bit_d:
div = bit_d[key] / normal_d[key]
if not 1 - epsilon < div < 1 + epsilon:
print(bit_d[key], normal_d[key], key, div)
return False
return True
test_randoms(8, 10 * 10**6)
```
Returns True
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]