Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change util.randrange to bit-wise #37

Closed
wants to merge 3 commits into from
Closed

Conversation

pik
Copy link
Contributor

@pik pik commented Jan 16, 2015

The current util.randrange runs up to worst case mean of 256 sys calls. This is, I think, the simplest way to implement bit-wise instead of byte-wise randrange. In terms of speed bit-wise is a lot more consistent (only where order is close to but less than (256**j) (It should be +2 but the original implementation calculated orderlen incorrectly) does it fall behind).

>>> timeit(randrange_old, order=generator_521.order(), n=10**5)
(0.0012479020285606384, 128.32433)  #mean time per run, mean os.urandom calls
>>> timeit(randrange_bit, order=generator_521.order(), n=10**5)
(6.894484043121337e-05, 1.0)   #mean time per run, mean os.urandom calls```

@pik pik force-pushed the develop branch 2 times, most recently from b42cce3 to 494c3a8 Compare January 16, 2015 19:48
else:
entropy_to_bits = lambda ent_256: ''.join(bin(ord(x))[2:].zfill(8) for x in ent_256)
if sys.version < '2.7': #Can't add a method to a built-in type so we are stuck with this
bit_length = lambda x: len(bin(2)) - 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean len(bin(x)) here?

@pik
Copy link
Contributor Author

pik commented Jan 28, 2015

@warner
You're right, I apologize, that was very careless.

Copy link
Member

@tomato42 tomato42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pik Could you rebase on top of current master?

@tomato42 tomato42 mentioned this pull request Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants