Skip to content

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

Closed
StanFromIreland wants to merge 2 commits into
python:mainfrom
StanFromIreland:patch-4
Closed

StanFromIreland wants to merge 2 commits into
python:mainfrom
StanFromIreland:patch-4

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented May 6, 2025 •

Copy link
Copy Markdown
Member

I believe the upper bound is not platform dependent.

Closes #133489


📚 Documentation preview 📚: https://cpython-previews--133529.org.readthedocs.build/

@skirpichev

Copy link
Copy Markdown
Member

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

rhettinger commented May 6, 2025 •

Copy link
Copy Markdown
Contributor

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

3 participants