Closed malachid closed 1 year ago
fastrand::seed
changes seed of thread local Rng
.fastrand::Rng::with_seed
creates a new instance of Rng
with the specified seed.fastrand::u8
uses thread local Rng
to generate u8.I.e., in the second example, the seed is not actually changed.
Closing as it is working as intended (Rng::with_seed
doesn't affect the thread-local Rng
). Once https://github.com/smol-rs/fastrand/pull/46 is merged, the compiler will show a useful warning in such cases.
warning: unused return value of `Rng::with_seed` that must be used
--> tests/smoke.rs:35:5
|
35 | fastrand::Rng::with_seed(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this creates a new instance of `Rng`; if you want to initialize the thread-local generator, use `fastrand::seed()` instead
Thanks for the quick clarification!
If you create a seeded generator using:
the value will be reproducible with each run.
If you instead do:
the value will be different on every run.
I believe the intention is that setting a seed would make runs reproducible.