# Command-line interface for the \`random\` module

**URL:** <https://discuss.python.org/t/command-line-interface-for-the-random-module/51304>\
**Category:** Ideas\
**Created:** [April 18, 2024, 2:32pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304 "2024-04-18T14:32:00Z")\
**Posts on this page:** 9\
**Page:** 3

<div class="post-metadata">

**Author:** ![will\_f](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/will_f/32/19106_2.png) [@will\_f](https://discuss.python.org/u/will_f)\
**Post date:** [June 22, 2024, 1:20pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/41 "2024-06-22T13:20:43Z")

</div>

This is an exciting idea, even beyond `random`. On the other hand, the inclination to stick with library development is understandable.

Here’s a hygiene related thought:

With `random` in particular, how the CLI interacts with [`random._inst`](https://github.com/python/cpython/blob/e58bece8cec39c1e7fa282bcfd069030aed7b905/Lib/random.py#L920C1-L920C6) should be considered. For example, if there’s somehow a case in which the CLI shares runtime with another program that’s keeping careful track of its progress through `random.getstate`, then CLI usage may corrupt the other program’s book-keeping. Might therefore be good for CLI to either know if it should use its own `random.Random` instance or just use one by default. Such scenarios don’t seem common, but might include runtimes like the Docker official image or Python kernel.

---

<div class="post-metadata">

**Author:** ![donBarbos](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/donbarbos/32/25833_2.png) [@donBarbos](https://discuss.python.org/u/donBarbos)\
**Post date:** [March 10, 2025, 3:45pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/42 "2025-03-10T15:45:41Z")

</div>

I’m not realized why the `--test` flag was added.  
I think it would be right to get rid of the `--test` flags in modules with cli.  
This flag is not documented and is not displayed in the `--help` output.

I suggest moving the tests, but I don’t know in what form because these are performance tests and I haven’t seen the practice of calling perf test from the cli module.

Maybe this flag is useful to someone and someone uses it, please tell me

---

<div class="post-metadata">

**Author:** ![Lucas\_Malor](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/lucas_malor/32/24845_2.png) [@Lucas\_Malor](https://discuss.python.org/u/Lucas_Malor)\
**Post date:** [March 10, 2025, 7:15pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/43 "2025-03-10T19:15:15Z")

</div>

I don’t understand the objections to the proposal. I think it will be very useful to have a CLI for `random`. CLI are also useful for who uses Python as a OS independent command line tool. Very useful for sysops and also for regular users.

I want to be more radical: i would like to see CLI also for `re`, `datetime`, `math`, `statistics` and `os`. But this is OT.

Anyway I didn’t know `uuid` has a CLI. It will save me a lot of time 🙂

---

<div class="post-metadata">

**Author:** ![juancer](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/juancer/32/26511_2.png) [@juancer](https://discuss.python.org/u/juancer)\
**Post date:** [March 10, 2025, 10:32pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/44 "2025-03-10T22:32:34Z")

</div>

Yes, I read part of the thread a couple of hours ago thanks to the update of @donBarbos and I was quickly impressed with the discovery. About `re`, @malemburg linked this thread some time ago: [Command line interface for the `re` module](https://discuss.python.org/t/command-line-interface-for-the-re-module/31819)

---

<div class="post-metadata">

**Author:** ![jrivers](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jrivers/32/12134_2.png) [@jrivers](https://discuss.python.org/u/jrivers)\
**Post date:** [March 11, 2025, 2:25am UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/45 "2025-03-11T02:25:30Z")

</div>

The proposal has already been implemented in Python 3.13.

---

<div class="post-metadata">

**Author:** ![donBarbos](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/donbarbos/32/25833_2.png) [@donBarbos](https://discuss.python.org/u/donBarbos)\
**Post date:** [March 11, 2025, 7:39am UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/46 "2025-03-11T07:39:33Z")

</div>

@hugovk Hi! Thank you for this feature.  
As far as I know many people prefer to remove flags for self-tests ([1](https://github.com/python/cpython/issues/130973#issuecomment-2708495698) [2](https://github.com/python/cpython/issues/130973#issuecomment-2709986584) [3](https://github.com/python/cpython/issues/93096#issuecomment-2710888839)).  
But in this module the flag `--test` is used for performance tests, maybe you can explain why it was added and whether anyone really uses it (or maybe we have a more convenient way)

---

<div class="post-metadata">

**Author:** ![merwok](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/merwok/32/29_2.png) [@merwok](https://discuss.python.org/u/merwok)\
**Post date:** [March 11, 2025, 2:12pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/47 "2025-03-11T14:12:24Z")

</div>

The objections are cleary expressed here (I would only replace «low quality» with «varying quality»):

> [@rhettinger](#):
>
> If we want to build a CLI toolset, it needs to be a deliberate collective decision and rather than a zoo of piecemeal one-offs. Ideally, all the CLIs would be in their own directory and have a project team with a vision and some standards. To me, the current list of CLI tooling looks seems like a random collection of low quality afterthought efforts with a couple exceptions for things we really do find useful during development and testing.

---

<div class="post-metadata">

**Author:** ![hugovk](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/hugovk/32/14505_2.png) [@hugovk](https://discuss.python.org/u/hugovk)\
**Post date:** [March 11, 2025, 10:03pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/48 "2025-03-11T22:03:24Z")

</div>

> [@donBarbos](#):
>
> As far as I know many people prefer to remove flags for self-tests ([1](https://github.com/python/cpython/issues/130973#issuecomment-2708495698) [2](https://github.com/python/cpython/issues/130973#issuecomment-2709986584) [3](https://github.com/python/cpython/issues/93096#issuecomment-2710888839)).  
> But in this module the flag `--test` is used for performance tests, maybe you can explain why it was added and whether anyone really uses it (or maybe we have a more convenient way)

As I wrote in the OP:

> [@hugovk](#):
>
> Currently, `python -m random` generates some sample test output. We could remove this, or if we still want it, move it to `python -m random --test`.

As I recall, no-one commented on this point either way, so I retained the sample output like this. I don’t think it’s really needed as we have unit tests.

But I suggest we close this old topic and open a new issue or topic if you want to remove `--test`.

---

<div class="post-metadata">

**Author:** ![davidism](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/davidism/32/3295_2.png) [@davidism](https://discuss.python.org/u/davidism)\
**Post date:** [March 11, 2025, 11:21pm UTC](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304/49 "2025-03-11T23:21:59Z")

</div>

Closed on March 11, 2025, 11:21pm UTC



[Previous page](https://discuss.python.org/t/command-line-interface-for-the-random-module/51304.md?page=2)
