Feature or enhancement
Proposal:
Many stdlib libraries have a simple CLI:
Some of my favourites:
$ python3 -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
$ python3 -m webbrowser https://www.python.org
$ python3 -m uuid
5f73cb76-01d7-4390-8cda-17fe9672a29f
$ python3 -m calendar
2024
January February March
Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su
1 2 3 4 5 6 7 1 2 3 4 1 2 3
[snip]
It would be useful to add a CLI to random to be randomly select a choice (using random.choice):
$ python3 -m random curry "fish n chips" tacos
fish n chips
We can also print a random number:
- if the input is an integer, print a random integer between 1 and the input (via
random.randint)
- if it's a float, print a random float between 0 and the input (via
random.uniform).
For example:
$ python3 -m random a b c
c
$ python3 -m random 6
4
$ python3 -m random 2.5
1.9597922929238814
Also with explicit arguments:
$ python3 -m random --choice a b c
b
$ python3 -m random --integer 6
6
$ python3 -m random --float 2.5
1.1778540129562416
$ python3 -m random --float 6
1.4311142568750403
This isn't a Python-specific tool, like pdb or pickletools, but a generally useful tool like http.server and uuid. I can't find an existing cross-platform tool for this. Linux has shuf 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 a num-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 to python -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
Feature or enhancement
Proposal:
Many stdlib libraries have a simple CLI:
Some of my favourites:
It would be useful to add a CLI to
randomto 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
pdborpickletools, but a generally useful tool likehttp.serveranduuid. I can't find an existing cross-platform tool for this. Linux hasshufto return a random choice, but it's not natively available in macOS (it's part of a Homebrew package) or Windows (uutilscan be installed using Scoop). There's also anum-utilspackage 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 randomgenerates 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
randommodule #118132