-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command-line interface for the random
module
#118131
Labels
3.13
bugs and security fixes
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
Comments
hugovk
added
type-feature
A feature request or enhancement
stdlib
Python modules in the Lib dir
3.13
bugs and security fixes
labels
Apr 21, 2024
I think this needs stronger support from python-dev on discuss before being added. |
hugovk
added a commit
that referenced
this issue
May 5, 2024
SonicField
pushed a commit
to SonicField/cpython
that referenced
this issue
May 8, 2024
@hugovk Do you think this issue can be closed? |
This was referenced Sep 11, 2024
andersk
added a commit
to andersk/cpython
that referenced
this issue
Sep 11, 2024
`python -m random --float N` incorrectly used a range between 1 and N of length N - 1. Fix it to use a range between 0 and N of length N, as originally specified in python#118131, and as everyone will expect. Fixes python#123968. Signed-off-by: Anders Kaseorg <[email protected]>
andersk
added a commit
to andersk/cpython
that referenced
this issue
Sep 11, 2024
`python -m random --float N` incorrectly used a range between 1 and N of length N - 1. Fix it to use a range between 0 and N of length N, as originally specified in python#118131, and as everyone will expect. Fixes python#123968. Signed-off-by: Anders Kaseorg <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
stdlib
Python modules in the Lib dir
type-feature
A feature request or enhancement
Feature or enhancement
Proposal:
Many stdlib libraries have a simple CLI:
Some of my favourites:
It would be useful to add a CLI to
random
to be randomly select a choice (usingrandom.choice
):We can also print a random number:
random.randint
)random.uniform
).For example:
Also with explicit arguments:
This isn't a Python-specific tool, like
pdb
orpickletools
, but a generally useful tool likehttp.server
anduuid
. I can't find an existing cross-platform tool for this. Linux hasshuf
to return a random choice, but it's not natively available in macOS (it's part of a Homebrew package) or Windows (uutils
can be installed using Scoop). There's also anum-utils
package for Unix to print a random integer.For me, just the random choice is the most important, but I can see at least picking a random integer is also useful, like a dice throw.
Currently,
python -m random
generates some sample test output; if we still need it I propose moving it topython -m random --test
.Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
Linked PRs
random
module #118132The text was updated successfully, but these errors were encountered: