Skip to content

python -m random --float N should pick a float between 0 and N, not 1 and N #123968

Closed
@andersk

Description

@andersk

Bug report

Bug description:

In the specification for the new python -m random CLI for 3.13 (#118131), the proposed behavior was

if it's a float, print a random float between 0 and the input (via random.uniform).

However, what was actually implemented (#118132, cc @hugovk) was

$ python -m random --help
[…]
  -f, --float N         print a random floating-point number between 1 and N inclusive
$ python -m random 2.0
1.883974829952927
$ python -m random 2.0
1.034610672623156
$ python -m random 2.0
1.3676261878147473
$ python -m random 2.0
1.1875340810783404
$ python -m random 2.0
1.6148479875565644
$ python -m random 1.0
1.0

This is surprising and not helpful. Everyone will expect a range of length N starting from 0.0, not a range of length N - 1.0 starting from 1.0.

(Note that this is completely distinct from the debate about whether it’s more natural to select integers from [1, …, N] or [0, …, N - 1], as at least those are both ranges of length N.)

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixesrelease-blockerstdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions