#random #secure-random #numbers

no-std rand_core

Core random number generator traits and tools for implementation

19 releases

new 0.9.0-beta.0 Nov 26, 2024
0.9.0-alpha.2 Jul 29, 2024
0.9.0-alpha.1 Mar 18, 2024
0.6.4 Sep 15, 2022
0.0.1 Sep 14, 2017

#933 in Algorithms

Download history 3179112/week @ 2024-08-06 3229969/week @ 2024-08-13 3311433/week @ 2024-08-20 3189897/week @ 2024-08-27 3412383/week @ 2024-09-03 3309042/week @ 2024-09-10 3417706/week @ 2024-09-17 3722557/week @ 2024-09-24 4384676/week @ 2024-10-01 4830400/week @ 2024-10-08 4663622/week @ 2024-10-15 3851535/week @ 2024-10-22 3587637/week @ 2024-10-29 3564747/week @ 2024-11-05 3724487/week @ 2024-11-12 3637976/week @ 2024-11-19

15,203,194 downloads per month
Used in 44,684 crates (1,096 directly)

MIT/Apache

60KB
729 lines

rand_core

Test Status Latest version Book API API

Core traits and error types of the rand library, plus tools for implementing RNGs.

This crate is intended for use when implementing the core trait, RngCore; it defines the core traits to be implemented as well as several small functions to aid in their implementation and types required for error handling.

The main rand crate re-exports most items defined in this crate, along with tools to convert the integer samples generated by RngCore to many different applications (including sampling from restricted ranges, conversion to floating point, list permutations and secure initialisation of RNGs). Most users should prefer to use the main rand crate.

Links:

Functionality

The rand_core crate provides:

  • base random number generator traits
  • error-reporting types
  • functionality to aid implementation of RNGs

The traits and error types are also available via rand.

Versions

The current version is:

rand_core = "0.6.4"

Rand libs have inter-dependencies and make use of the semver trick in order to make traits compatible across crate versions. (This is especially important for RngCore and SeedableRng.) A few crate releases are thus compatibility shims, depending on the next lib version (e.g. rand_core versions 0.2.2 and 0.3.1). This means, for example, that rand_core_0_4_0::SeedableRng and rand_core_0_3_0::SeedableRng are distinct, incompatible traits, which can cause build errors. Usually, running cargo update is enough to fix any issues.

Crate Features

rand_core supports no_std and alloc-only configurations, as well as full std functionality. The differences between no_std and full std are small, comprising RngCore support for Box<R> types where R: RngCore, std::io::Read support for types supporting RngCore, and extensions to the Error type's functionality.

The std feature is not enabled by default. This is primarily to avoid build problems where one crate implicitly requires rand_core with std support and another crate requires rand without std support. However, the rand crate continues to enable std support by default, both for itself and rand_core.

The serde feature can be used to derive Serialize and Deserialize for RNG implementations that use the BlockRng or BlockRng64 wrappers.

License

rand_core is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT, and COPYRIGHT for details.

Dependencies

~1MB
~15K SLoC