You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `rust-random` libraries make limited commitments to reproducibility of seedable PRNGs and stochastic algorithms.
4
4
5
-
Given fixed inputs, all items (should) fall into one of three categories:
5
+
This chapter concerns value-stability of deterministic processes using the `rust-random` libraries.
6
6
7
-
- Output is non-deterministic, thus never reproducible (example: `rand::rng`)
8
-
- Output is deterministic, but not considered portable (`SmallRng`, `StdRng`; limitations below)
9
-
- Output is deterministic and portable (named RNGs; most distributions, sampling and shuffling algorithms)
7
+
## API-breaking, value-breaking and SemVer
10
8
11
-
In general, functionality is considered deterministic and portable *unless*
12
-
it is clearly non-deterministic (e.g. `getrandom`, `ThreadRng`) *or* it is
13
-
documented as being nonportable (e.g. `StdRng`, `SmallRng`).
9
+
A change (to a library) is considered **API-breaking** if it may cause a compilation failure of code which was compatible with a prior version of the API, or is otherwise an incompatible change.
14
10
15
-
## Crate versions
11
+
We aim to follow [SemVer rules](https://semver.org/) regarding API-breaking changes and `MAJOR.MINOR.PATCH`versions. That is, post 1.0, new minor versions should not introduce API-breaking changes.
16
12
17
-
We try to follow [semver rules](https://semver.org/) regarding
18
-
API-breaking changes and `MAJOR.MINOR.PATCH` versions:
13
+
A change is considered **value-breaking** if it is not API-breaking yet would result in changed output values of a deterministic stochastic process using only unchanged parts of the `rust-random` API.
19
14
20
-
- New *patch* versions should not include API-breaking changes or major new
21
-
features
22
-
- Before 1.0, *minor* versions may include API breaking changes. After 1.0
23
-
they should not.
15
+
Value-breaking changes are permitted in minor versions.
24
16
25
-
Additionally, we must also consider *value-breaking changes* and *portability*.
26
-
When given fixed inputs,
17
+
## Non-portable deterministic items
27
18
28
-
- For non-deterministic items, implementations may change in any release
29
-
- For deterministic nonportable items, output should be preserved in patch
30
-
releases, but may change in any minor release (including after 1.0)
31
-
- For portable items, output should be preserved by patch releases.
32
-
Minor releases (including after 1.0) may include such value-breaking
33
-
changes, though these must be documented in the CHANGELOG.
19
+
An item in a `rust-random` API (such as a struct or function) may be declared to be **non-portable**, meaning that it opts out of all reproducibility guarantees. Non-portable items may be deterministic, yet yield different results on different platforms and library versions (they may make value-breaking changes in any release).
20
+
21
+
This is a change in policy affecting `rand` from version `0.10` or `1.0` (whichever release is next); up to version `0.9` non-portable items were not permitted to make value-breaking changes in patch releases.
22
+
23
+
This non-portable declaration must be clearly mentioned in documentation. The following items make such a declaration:
Some items are clearly non-deterministic (e.g. [`rand::rng`]). Some items are deterministic but non-portable (above). All other parts of the public API of `rust-random` crates (including PRNGs, distributions and other stochastic algorithms) are expected to be portable:
31
+
32
+
- Results should be reproducible across platforms
33
+
- Results should be reproducible across patch releases
34
+
- Minor releases, including after 1.0, may make value-breaking changes to portable items. Such changes must be well motivated and should be clearly mentioned in the CHANGELOG.
34
35
35
36
### Testing
36
37
37
-
We expect all pseudo-random algorithms to test the value-stability of their
38
-
output, where possible:
38
+
We expect all portable stochastic algorithms to test the value-stability of their output with some form of test vector.
39
39
40
-
- PRNGs should be compared with a reference vector ([example](https://github.com/rust-random/rngs/blob/master/rand_xoshiro/src/xoshiro256starstar.rs#L124))
40
+
- PRNGs should test against a reference vector where available ([example](https://github.com/rust-random/rngs/blob/master/rand_xoshiro/src/xoshiro256starstar.rs#L122))
41
41
- Other algorithms should include their own test vectors within a
42
42
`value_stability` test or similar ([example](https://github.com/rust-random/rand/blob/master/src/distr/bernoulli.rs#L226))
43
43
44
+
## Support for prior versions
45
+
46
+
We aim to support users of `rust-random` crates using a prior `MAJOR.MINOR` version for the purposes of reproducibility by:
47
+
48
+
- Providing security fixes as patch versions where appropriate
49
+
- Facilitating the back-porting of compatible additions from future crate versions *on request*
50
+
- Other fixes may be considered for back-porting, but are often not possible without API-breaking or value-breaking changes
51
+
44
52
## Limitations
45
53
46
54
### Portability of usize
@@ -54,10 +62,7 @@ it does matter.
54
62
A simple rule follows: if portability is required, *never* sample a `usize` or
55
63
`isize` value directly.
56
64
57
-
Within Rand we adhere to this rule whenever possible. All sequence-related
58
-
code requiring a bounded `usize` value will sample a `u32` value unless the
59
-
upper bound exceeds `u32::MAX`.
60
-
(Note that this actually improves benchmark performance in many cases.)
65
+
From `rand v0.9`, `isize` and `usize` types are no longer supported in many parts of the public API, including [`StandardUniform`]. `usize` is supported by [`SampleUniform`] and thus [`Rng::random_range`], using `u32` sampling whenever possible to maximise portability.
61
66
62
67
### Portability of floats
63
68
@@ -66,3 +71,8 @@ implementation details. In particular, the results of transcendental functions v
66
71
from platform to platform. Due to this, results of distributions in `rand_distr` using `f32` or `f64` may not be portable.
67
72
68
73
To alleviate (or further complicate) this concern, we prefer to use `libm` over `std` implementations of these transcendental functions. See [rand_distr features](crate-features.html#rand_distr-features).
0 commit comments