Skip to content

Comments

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

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

gh-133489: Document random.randbytes bounds.#133529
StanFromIreland wants to merge 2 commits intopython:mainfrom
StanFromIreland:patch-4

Conversation

@StanFromIreland
Copy link
Member

@StanFromIreland StanFromIreland commented May 6, 2025

@skirpichev
Copy link
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
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