Skip to content

random.triangular returns infinity for finite bounds when their difference overflows #158743

Description

@augusto-rehfeldt

Bug report

Bug description:

Documented behaviour: "Continuous distribution bounded by given lower and upper limits, and having a given mode value in-between." — Random.triangular docstring.

Expected: A finite sample in [-1e308, 1e308].

Actual: random.triangular(-1e308, 1e308, None) returns -inf after random.seed(0).

import random, math

seed, low, high, mode = inp = (0, -1e308, 1e308, None)
if not (math.isfinite(low) and math.isfinite(high) and low < high and mode is None):
    print("REFUTATION REJECTED:", inp, "invalid input")
else:
    random.seed(seed)
    actual = random.triangular(low, high, mode)
    if not low <= actual <= high:
        print("REFUTATION CONFIRMED:", inp, "actual=", actual, "expected=", (low, high))
    else:
        print("REFUTATION REJECTED:", inp, "sample is within the documented interval")

Output on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library random:

REFUTATION CONFIRMED: (0, -1e+308, 1e+308, None) actual= -inf expected= (-1e+308, 1e+308)

This report was found and written by an automated property-testing tool I run (bugforge). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/random-20261003-034345-c3

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions