# Rand crate observation

**URL:** <https://users.rust-lang.org/t/rand-crate-observation/142729>\
**Category:** community\
**Created:** [September 30, 2026, 11:04am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729 "2026-09-30T11:04:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MD-FAHAD25624](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/md-fahad25624/32/52939_2.png) [@MD-FAHAD25624](https://users.rust-lang.org/u/MD-FAHAD25624)\
**Post date:** [September 30, 2026, 11:04am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/1 "2026-09-30T11:04:10Z")

</div>

Why is the rand crate not included in the standard library, rather another dependency, despite it's requirements?

---

<div class="post-metadata">

**Author:** ![ZiCog](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicog/32/12216_2.png) [@ZiCog](https://users.rust-lang.org/u/ZiCog)\
**Post date:** [September 30, 2026, 11:18am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/2 "2026-09-30T11:18:42Z")

</div>

I have no idea really but I make the observation that over the course of computer history all kind of languages and all kind of operating systems have offered a rand() function of some kind and they have been found to be defective. Indeed infamous for their catastrophic design flaws, predictability, or structural biases. You can find examples in C++, Fortran, Javascript, PHP, Python, all kind of BASIC, Linux, Windows and BSD.

So I conclude it's a very good idea for Rust not to fix on any rand in its standard library.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jdahlstrom/32/38017_2.png) [@jdahlstrom](https://users.rust-lang.org/u/jdahlstrom)\
**Post date:** [September 30, 2026, 12:26pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/3 "2026-09-30T12:26:56Z")

</div>

Because libraries go to the std to die. It has not been obvious that the rand API is the right one to be stabilized and set in stone forever. The C++11 random API is a cautionary example that was seemingly well-thought-out and "the API that other random APIs want to be", yet it turned out to be suboptimal in several important aspects that are almost impossible to fix backwards compatibly.

There is now a very small randomness API in the nightly std which is in process to be stabilized. However, even this extremely minimal interface has several unresolved questions.

---

<div class="post-metadata">

**Author:** ![miro](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@miro](https://users.rust-lang.org/u/miro)\
**Post date:** [September 30, 2026, 3:05pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/4 "2026-09-30T15:05:45Z")

</div>

I am not sure if this question makes sense, but do all std targets and all targets that may support std in the future allow random number generation? what if a std target is perfectly deterministic?

---

<div class="post-metadata">

**Author:** ![farnz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/farnz/32/14366_2.png) [@farnz](https://users.rust-lang.org/u/farnz)\
**Post date:** [September 30, 2026, 3:23pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/5 "2026-09-30T15:23:39Z")

</div>

`rand` supplies PRNGs for that purpose, which are fully deterministic if you know the internal state, along with the [`SeedableRng`](https://docs.rs/rand/latest/rand/trait.SeedableRng.html#foreign-impls) trait for setting the internal state of a PRNG.

For example, there's the [`ChaCha20Rng`](https://docs.rs/rand/latest/rand/rngs/struct.ChaCha20Rng.html), which uses the ChaCha cipher to encrypt a stream of 64-bit counter values, using the seed as the cryptographic secret. If you can predict this PRNG's output without the seed, you've broken the ChaCha cipher it uses.

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/quinedot/32/17693_2.png) [@quinedot](https://users.rust-lang.org/u/quinedot)\
**Post date:** [September 30, 2026, 6:43pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/6 "2026-09-30T18:43:29Z")

</div>

> [@jdahlstrom](#):
>
> Because libraries go to the std to die. It has not been obvious that the rand API is the right one to be stabilized and set in stone forever.

In case you didn't know, what they mean here is that `std` has strict backward compatibility requirements (it's been on the same SemVer version since 2015 and there are no plans to change that). That means even deprecated APIs have to be maintained forever.

With that in mind [check out the changes `rand` has made over the years.](https://rust-random.github.io/book/update.html) The last two incompatible 0.x.0 releases being in January 2025 and February 2026.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kornel/32/4823_2.png) [@kornel](https://users.rust-lang.org/u/kornel)\
**Post date:** [October 1, 2026, 12:02am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/7 "2026-10-01T00:02:11Z")

</div>

rand has made **10** semver-major releases so far, refining its API to be safer, faster, more powerful. It turns out to be tricky to provide strong randomness + thread safety + performance + ergonomics at the same time!

in std the max semver-major releases is **1**. It has to be right on the first try and then you have to live with it forever.

Perhaps it could be added now, assuming 10 iterations should be good enough, and by avoiding promising too much about specifics of the PRNG algorithms.

---

<div class="post-metadata">

**Author:** ![MOCKBA](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/mockba/32/41423_2.png) [@MOCKBA](https://users.rust-lang.org/u/MOCKBA)\
**Post date:** [October 1, 2026, 12:09am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/8 "2026-10-01T00:09:49Z")

</div>

Rand can't be reliable, and Rust refuses everything not reliable. You won't find regex too.

---

<div class="post-metadata">

**Author:** ![Redglyph](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/redglyph/32/27961_2.png) [@Redglyph](https://users.rust-lang.org/u/Redglyph)\
**Post date:** [October 1, 2026, 7:03am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/9 "2026-10-01T07:03:41Z")

</div>

> [@kornel](#):
>
> Perhaps it could be added now, assuming 10 iterations should be good enough, and by avoiding promising too much about specifics of the PRNG algorithms.

I see it's version 0.10.3, now, so technically it should be considered unstable. From the README, is seems to be on purpose.

> ## Versions
> 
> Rand is _mature_ (suitable for general usage, with infrequent breaking releases which minimise breakage) but not yet at 1.0. Current `MAJOR.MINOR` versions are:
> 
> - Version 0.10 was released in February 2026.

Many crates seem shy to get to version 1.0, even when they're mature. I wonder if that's because Rust is considered more safe than many other languages.

---

<div class="post-metadata">

**Author:** ![simonbuchan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/simonbuchan/32/19939_2.png) [@simonbuchan](https://users.rust-lang.org/u/simonbuchan)\
**Post date:** [October 2, 2026, 8:35am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/10 "2026-10-02T08:35:41Z")

</div>

It was extremely common in npm too... until npm changed the default from 0.1.0 to 1.0.0 for a new project. Sometimes it's the dumbest little things...

---

<div class="post-metadata">

**Author:** ![conqp](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/conqp/32/42559_2.png) [@conqp](https://users.rust-lang.org/u/conqp)\
**Post date:** [October 2, 2026, 10:41am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/11 "2026-10-02T10:41:46Z")

</div>

At the risk of side-tracking even more, I believe that many crates are afraid of rolling breaking changes. Semver was introduced to be able to distinguish different types of changes, not to _discourage_ major releases. In my experience software is always just a best guess at the moment it was written to solve a specific problem. Changes to ecosystems, requirements or new insights may lead to the necessity of changes, even breaking ones. This, imho, is not something _bad_, but rather something that is occasionally _necessary_, which is why I am wary of remarks like

> [@kornel](#):
>
> in std the max semver-major releases is **1**. It has to be right on the first try and then you have to live with it forever.

I am aware that this is not a single person's opinion here, but still, I think that this notion from the Rust dev team attempts to bypass reality.

---

<div class="post-metadata">

**Author:** ![farnz](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/farnz/32/14366_2.png) [@farnz](https://users.rust-lang.org/u/farnz)\
**Post date:** [October 2, 2026, 1:24pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/12 "2026-10-02T13:24:44Z")

</div>

> [@conqp](#):
>
> At the risk of side-tracking even more, I believe that many crates are afraid of rolling breaking changes. Semver was introduced to be able to distinguish different types of changes, not to _discourage_ major releases. In my experience software is always just a best guess at the moment it was written to solve a specific problem. Changes to ecosystems, requirements or new insights may lead to the necessity of changes, even breaking ones. This, imho, is not something _bad_, but rather something that is occasionally _necessary_, which is why I am wary of remarks like

The flip side of breaking changes is that every time you make a breaking change, all code that worked before the change has to be checked for compatibility with the change. Often the compiler can help with this, but it's still a nuisance if your code that used to compile no longer does after updating to the latest version of a dependency - and it's more of a problem if updating to the latest change compiles, but no longer works as you expected.

How big a problem this is depends on how "foundational" your code is; a leaf crate like [`companies-house-api`](https://crates.io/crates/companies-house-api) with very few dependents (none public) doesn't see much of a problem with breaking changes - the cost of checking and applying needed fixes after a breaking change is low, and so a breaking change doesn't have to be that much of a win to be a net gain.

At the other extreme, [`core`](https://doc.rust-lang.org/core/index.html) is completely foundational. If `core` has any breaking changes, then all Rust code needs to be checked and any necessary fixes applied after the change. This is a huge amount of work - the cost of checking and applying needed fixes after a breaking change is very high, and as a result, a breaking change has to be a huge benefit to be worth making, otherwise it's a net loss for the ecosystem (see the Python 2 to Python 3 transition for an example, which took 12 years just to be declared "done", and which still isn't finished in the wider ecosystem, with some people still sticking to Python 2.7.10 because they won't pay the cost of the Python 2 to 3 breaking change).

And that, not SemVer, is what pushes back hard on breaking changes; the cost of a breaking change goes up as you affect more code, and the cost of maintaining two or more branches indefinitely so that your dependents can catch up with the breaking change is also significant. A consequence of this is that the value of a breaking change has to get bigger as you affect more dependents - and as `std` affects a majority of Rust code in the wild, a breaking change has to have huge value to be worth the cost.

---

<div class="post-metadata">

**Author:** ![ekuber](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/ekuber/32/3875_2.png) [@ekuber](https://users.rust-lang.org/u/ekuber)\
**Post date:** [October 2, 2026, 3:43pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/13 "2026-10-02T15:43:20Z")

</div>

> I think that this notion from the Rust dev team attempts to bypass reality.

There are technical reasons for why std can't break. When passing an Option from one crate to another they both _must_ be the same. The crates ecosystem sidesteps this problem by letting you have more than one crate version in your tree, but the way things are set up today there can be only one std. I do think that a stdx crate approach would be reasonable. There have been a few attempts, that have petered out for one reason or another.

---

<div class="post-metadata">

**Author:** ![simonbuchan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/simonbuchan/32/19939_2.png) [@simonbuchan](https://users.rust-lang.org/u/simonbuchan)\
**Post date:** [October 2, 2026, 9:39pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/14 "2026-10-02T21:39:16Z")

</div>

Honestly maybe the biggest problem with having stuff in std is that it causes people to think more stuff should be in std (eg, this topic!)

If Rust had/could have gone a more Deno approach where the "standard library" was just a crate no different to any other crate we wouldn't have this expectation that the language is "deficient" if you have to get a crate for some feature: you have to get a crate for every feature! (Theoretically it would also allow breaking changes with a bit less pain, if you were real careful about how it was implemented so multiple versions of std could work together.)

It's rather late for that change, though 🙃

---

<div class="post-metadata">

**Author:** ![Redglyph](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/redglyph/32/27961_2.png) [@Redglyph](https://users.rust-lang.org/u/Redglyph)\
**Post date:** [October 3, 2026, 8:22am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/15 "2026-10-03T08:22:14Z")

</div>

Yes,I suppose it makes sense not to put too much in std, and it's not an easy balancing exercise, either.

I think that what we miss is an "official" extension or rather a group of crates that have a large common interest, like RNG, regular expressions, extra iterator adaptors, error management, serdes, ... There are known crates for all of those, of course, but I think it's confusing for programmers who are not used to it, especially when there are several potential crate candidates and it's not easy to assess them.

I suppose it just requires some getting used to and some time to get to know the ecosystem.

---

<div class="post-metadata">

**Author:** ![ZiCog](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/zicog/32/12216_2.png) [@ZiCog](https://users.rust-lang.org/u/ZiCog)\
**Post date:** [October 3, 2026, 9:55am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/16 "2026-10-03T09:55:30Z")

</div>

> [@Redglyph](#):
>
> I think it's confusing for programmers who are not used to it,

A programmer new to Rust needs random numbers (for example) and does not know how. Typically today we would expect he goes to google and finds out. How is that more or less confusing if what he finds is in the standard library or in a crate on [crates.io](http://crates.io)?

There is the issue of adding an entry to Cargo.toml but that is almost nothing and an LLM user will not even notice.

---

<div class="post-metadata">

**Author:** ![mroth](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mroth](https://users.rust-lang.org/u/mroth)\
**Post date:** [October 3, 2026, 11:36am UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/17 "2026-10-03T11:36:38Z")

</div>

Should `std` omit functionality to prevent people doing stupid things? I'm not sure. Virtual every function from `std` can be used to do stupid things in some ways: A `Vec` can be filled until OOM, using `std::fs` important files can be modified and deleted, etc.

For many use cases, a simple, flawed pseudo random generator seeded with the current time is good enough. Maybe naming the method `pseudo_random()` or something like this would be a hint to users, there might be an issue with the generated numbers.

---

<div class="post-metadata">

**Author:** ![kornel](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kornel/32/4823_2.png) [@kornel](https://users.rust-lang.org/u/kornel)\
**Post date:** [October 3, 2026, 12:27pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/18 "2026-10-03T12:27:10Z")

</div>

It would be good to remove `std::fs` from libstd, because that design can't work with Web `FileSystem` API and can't support capability-based security and has problems with TOCTOU due to lack of handles for directories. If it was a crate, users could choose a more appropriate version of the API, or stay on the basic 1.0.

---

<div class="post-metadata">

**Author:** ![jumpnbrownweasel](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jumpnbrownweasel/32/17403_2.png) [@jumpnbrownweasel](https://users.rust-lang.org/u/jumpnbrownweasel)\
**Post date:** [October 3, 2026, 4:35pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/19 "2026-10-03T16:35:00Z")

</div>

> [@Redglyph](#):
>
> I think that what we miss is an "official" extension or rather a group of crates that have a large common interest

A related proposal:

> **[Battery packs: Let's talk about crates, baby · baby steps](https://smallcultfollowing.com/babysteps/blog/2026/07/15/battery-packs/)**

---

<div class="post-metadata">

**Author:** ![tczajka](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/tczajka/32/24743_2.png) [@tczajka](https://users.rust-lang.org/u/tczajka)\
**Post date:** [October 3, 2026, 6:30pm UTC](https://users.rust-lang.org/t/rand-crate-observation/142729/20 "2026-10-03T18:30:31Z")

</div>

I think `HashSet`, `HashMap`, `VecDeque`, `BinaryHeap` should not be in `std`.

`BTreeSet` can do `BinaryHeap`'s job, and if you wanted a really optimized priority queue it wouldn't be a _binary_ heap (that's not cache efficient).

`BTreeMap` can for the most part do what `HashMap` does without its hashing choices and randomness.

All the basic collection needs are met by `Vec` and `BTreeSet`/`BTreeMap`.

[Next page](https://users.rust-lang.org/t/rand-crate-observation/142729.md?page=2)
