Skip to content

check errors first before starting on work in random module #154973

Description

@lbaumbauer

Bug report

Bug description:

        u = self.random()

(

u = self.random()
)
This line is ran even when the error case happens, which is unnecessary work. There is no disadvantage to moving the check upwards as the check is ran every time.

The check:
try: c = 0.5 if mode is None else (mode - low) / (high - low) except ZeroDivisionError: return low

CPython versions tested on:

3.13

Operating systems tested on:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions