| 1 |
# rand_core |
| 2 |
|
| 3 |
[](https://github.com/rust-random/rand/actions) |
| 4 |
[](https://crates.io/crates/rand_core) |
| 5 |
[](https://rust-random.github.io/book/) |
| 6 |
[](https://rust-random.github.io/rand/rand_core) |
| 7 |
[](https://docs.rs/rand_core) |
| 8 |
[](https://github.com/rust-random/rand#rust-version-requirements) |
| 9 |
|
| 10 |
Core traits and error types of the [rand] library, plus tools for implementing |
| 11 |
RNGs. |
| 12 |
|
| 13 |
This crate is intended for use when implementing the core trait, `RngCore`; it |
| 14 |
defines the core traits to be implemented as well as several small functions to |
| 15 |
aid in their implementation and types required for error handling. |
| 16 |
|
| 17 |
The main [rand] crate re-exports most items defined in this crate, along with |
| 18 |
tools to convert the integer samples generated by `RngCore` to many different |
| 19 |
applications (including sampling from restricted ranges, conversion to floating |
| 20 |
point, list permutations and secure initialisation of RNGs). Most users should |
| 21 |
prefer to use the main [rand] crate. |
| 22 |
|
| 23 |
Links: |
| 24 |
|
| 25 |
- [API documentation (master)](https://rust-random.github.io/rand/rand_core) |
| 26 |
- [API documentation (docs.rs)](https://docs.rs/rand_core) |
| 27 |
- [Changelog](https://github.com/rust-random/rand/blob/master/rand_core/CHANGELOG.md) |
| 28 |
|
| 29 |
[rand]: https://crates.io/crates/rand |
| 30 |
|
| 31 |
|
| 32 |
## Functionality |
| 33 |
|
| 34 |
The `rand_core` crate provides: |
| 35 |
|
| 36 |
- base random number generator traits |
| 37 |
- error-reporting types |
| 38 |
- functionality to aid implementation of RNGs |
| 39 |
|
| 40 |
The traits and error types are also available via `rand`. |
| 41 |
|
| 42 |
## Versions |
| 43 |
|
| 44 |
The current version is: |
| 45 |
``` |
| 46 |
rand_core = "0.6.0" |
| 47 |
``` |
| 48 |
|
| 49 |
Rand libs have inter-dependencies and make use of the |
| 50 |
[semver trick](https://github.com/dtolnay/semver-trick/) in order to make traits |
| 51 |
compatible across crate versions. (This is especially important for `RngCore` |
| 52 |
and `SeedableRng`.) A few crate releases are thus compatibility shims, |
| 53 |
depending on the *next* lib version (e.g. `rand_core` versions `0.2.2` and |
| 54 |
`0.3.1`). This means, for example, that `rand_core_0_4_0::SeedableRng` and |
| 55 |
`rand_core_0_3_0::SeedableRng` are distinct, incompatible traits, which can |
| 56 |
cause build errors. Usually, running `cargo update` is enough to fix any issues. |
| 57 |
|
| 58 |
## Crate Features |
| 59 |
|
| 60 |
`rand_core` supports `no_std` and `alloc`-only configurations, as well as full |
| 61 |
`std` functionality. The differences between `no_std` and full `std` are small, |
| 62 |
comprising `RngCore` support for `Box<R>` types where `R: RngCore`, |
| 63 |
`std::io::Read` support for types supporting `RngCore`, and |
| 64 |
extensions to the `Error` type's functionality. |
| 65 |
|
| 66 |
The `std` feature is *not enabled by default*. This is primarily to avoid build |
| 67 |
problems where one crate implicitly requires `rand_core` with `std` support and |
| 68 |
another crate requires `rand` *without* `std` support. However, the `rand` crate |
| 69 |
continues to enable `std` support by default, both for itself and `rand_core`. |
| 70 |
|
| 71 |
The `serde1` feature can be used to derive `Serialize` and `Deserialize` for RNG |
| 72 |
implementations that use the `BlockRng` or `BlockRng64` wrappers. |
| 73 |
|
| 74 |
|
| 75 |
# License |
| 76 |
|
| 77 |
`rand_core` is distributed under the terms of both the MIT license and the |
| 78 |
Apache License (Version 2.0). |
| 79 |
|
| 80 |
See [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT), and |
| 81 |
[COPYRIGHT](COPYRIGHT) for details. |