Skip to content

random.vonmisesvariate() and random.lognormvariate() accept invalid parameters despite docs constraints #135647

Open
@denini08

Description

@denini08

Bug report

Bug description:

While reading the Python documentation for the random module, I noticed something that looks inconsistent between the documentation and the actual behavior of the code.

The documentation for the functions random.vonmisesvariate() and random.lognormvariate() states some restrictions for their parameters link:

  • For vonmisesvariate(mu, kappa), it says that "kappa must be greater than or equal to zero".
  • For lognormvariate(mu, sigma), it says that "sigma must be greater than zero".

However, the functions do not raise any error when invalid values are passed:

import random

print(random.vonmisesvariate(1, -2))   # No error
print(random.lognormvariate(1, -2))    # No error

Both functions run without any exception, even though the parameters do not meet the constraints described in the documentation.

I am wondering if this is something that should be addressed. Should the functions validate their parameters and raise an error (e.g., ValueError) for invalid inputs? Or maybe the documentation should be updated to clarify that these constraints are mathematical recommendations rather than enforced by code?

I just wanted to report this inconsistency between the documentation and the code behavior and ask for your opinion about whether this should be considered a bug or a documentation issue.

CPython versions tested on:

3.15

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions