Skip to content

os urandom does not document CCRandomGenerateBytes #116245

Closed

Description

@RappelBerryPi

Documentation

The documentation for os.urandom clearly states that for Linux systems getrandom() is used when available (and then depending on python release and Linux version the behavior changes).

The documentation also clearly states that for Windows os.urandom uses BCryptGenRandom (which was previously CryptGenRandom before release 3.11).

The documentation then states that on a "Unix-like system" that reads to /dev/urandom are done.

However macOS is not mentioned (which could technically be covered by the "Unix-like system" and is often misinterpreted that way).

The /mimalloc/prim/unix/prim.c file (around lines 730-760) define macOS functionality using CCRandomGenerateBytes and then falling back to arc4random_buf.

The above functionality should be documented.

Linked PRs

Activity

  1. ronaldoussoren commented on Mar 3, 2024

    @ronaldoussoren
    Contributor

    The documentation is not up to date, but not in the way you mention. The implementation for os.urandom in the end calls pyurandom in Python/bootstrap.c, and that calls getentropy(3) on macOS 10.12 or later and reads from /dev/urandom on older versions of macOS.

    The fact that getentropy is used is only mentioned in a version changed notice that only mentions OpenBSD.

  2. RappelBerryPi commented on Mar 3, 2024

    @RappelBerryPi
    Author

    Thank you for the correction of my misunderstanding.

    Also thank you for updating the doc.

  3. added 3 commits that reference this issue on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions