Skip to content

gh-133489: Document random.randbytes bounds. #133529

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

Closed
wants to merge 2 commits into from

Conversation

StanFromIreland
Copy link
Contributor

@StanFromIreland StanFromIreland commented May 6, 2025

@skirpichev
Copy link
Contributor

I believe the upper bound is not platform dependent.

Mentioned limit holds just because n*8 in randbytes(n) should fit int's size. Typically it's 4 bytes, thus your 2 ** 28. But I'm not sure it's platform-independent.

@rhettinger rhettinger self-assigned this May 6, 2025
@rhettinger
Copy link
Contributor

rhettinger commented May 6, 2025

This isn't something we normally document. Consider len(range(2**65)) for example. To some degree, OverflowErrors speak for themselves. Also, putting a note like this in the docs doesn't really help the reader.

Also, this isn't specific to randbytes. This happens upstream with the random.getrandbits(8 * 2 ** 28) call.

@rhettinger rhettinger closed this May 6, 2025
@StanFromIreland StanFromIreland deleted the patch-4 branch May 6, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Possible unnecessary OverflowError in random.getrandbits
3 participants