This repository was archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Simplify _rand_exp #7
Copy link
Copy link
Open
Description
The current _rand_exp is currently looking suboptimal:
# Exp2 generates n with probability 1/2^(n+1).
@staticmethod
def _rand_exp():
rand_bin = bin(int(random.random() * 2**32-1))[2:]
rand_bin = '0'*(32 - len(rand_bin)) + rand_bin
count = 0
for i in rand_bin:
if i == '0':
count +=1
else:
break
return countAm I misreading the code and the comment, or is it equivalent to int(random.expovariate(0.5))?
Metadata
Metadata
Assignees
Labels
No labels