Debian Codegraph @

debian/rust-vendor/rand/README.md

raw
1 # Rand
2
3 [![Test Status](https://github.com/rust-random/rand/actions/workflows/test.yml/badge.svg?event=push)](https://github.com/rust-random/rand/actions)
4 [![Crate](https://img.shields.io/crates/v/rand.svg)](https://crates.io/crates/rand)
5 [![Book](https://img.shields.io/badge/book-master-yellow.svg)](https://rust-random.github.io/book/)
6 [![API](https://docs.rs/rand/badge.svg)](https://docs.rs/rand)
7
8 Rand is a set of crates supporting (pseudo-)random generators:
9
10 - Built over a standard RNG trait: [`rand_core::RngCore`](https://docs.rs/rand_core/latest/rand_core/trait.RngCore.html)
11 - With fast implementations of both [strong](https://rust-random.github.io/book/guide-rngs.html#cryptographically-secure-pseudo-random-number-generators-csprngs) and
12 [small](https://rust-random.github.io/book/guide-rngs.html#basic-pseudo-random-number-generators-prngs) generators: [`rand::rngs`](https://docs.rs/rand/latest/rand/rngs/index.html), and more RNGs: [`chacha20`](https://docs.rs/chacha20), [`rand_xoshiro`](https://docs.rs/rand_xoshiro/), [`rand_pcg`](https://docs.rs/rand_pcg/), [`rand_sfc`](https://docs.rs/rand_sfc/), [`rand_seeder`](https://docs.rs/rand_seeder/), [rngs repo](https://github.com/rust-random/rngs/)
13 - [`rand::rng`](https://docs.rs/rand/latest/rand/fn.rng.html) is an asymptotically-fast, automatically-seeded and reasonably strong generator available on all `std` targets
14 - Direct support for seeding generators from the [getrandom] crate
15
16 With broad support for random value generation and random processes:
17
18 - [`StandardUniform`](https://docs.rs/rand/latest/rand/distr/struct.StandardUniform.html) random value sampling,
19 [`Uniform`](https://docs.rs/rand/latest/rand/distr/struct.Uniform.html)-ranged value sampling
20 and [more](https://docs.rs/rand/latest/rand/distr/index.html)
21 - Samplers for a large number of non-uniform random number distributions via our own
22 [`rand_distr`](https://docs.rs/rand_distr) and via
23 the [`statrs`](https://docs.rs/statrs)
24 - Random processes (mostly choose and shuffle) via [`rand::seq`](https://docs.rs/rand/latest/rand/seq/index.html) traits
25
26 All with:
27
28 - [Portably reproducible output](https://rust-random.github.io/book/portability.html)
29 - `#[no_std]` compatibility (partial)
30 - *Many* performance optimisations thanks to contributions from the wide
31 user-base
32
33 Rand **is not**:
34
35 - Small (LoC). Most low-level crates are small, but the higher-level `rand`
36 and `rand_distr` each contain a lot of functionality.
37 - Simple (implementation). We have a strong focus on correctness, speed and flexibility, but
38 not simplicity. If you prefer a small-and-simple library, there are
39 alternatives including [fastrand](https://crates.io/crates/fastrand)
40 and [oorandom](https://crates.io/crates/oorandom).
41 - Primarily a cryptographic library. `rand` does provide some generators which
42 aim to support unpredictable value generation under certain constraints;
43 see [SECURITY.md](https://github.com/rust-random/rand/blob/master/SECURITY.md) for details.
44 Users are expected to determine for themselves
45 whether `rand`'s functionality meets their own security requirements.
46
47 Documentation:
48
49 - [The Rust Rand Book](https://rust-random.github.io/book)
50 - [API reference (docs.rs)](https://docs.rs/rand)
51
52
53 ## Versions
54
55 Rand is *mature* (suitable for general usage, with infrequent breaking releases
56 which minimise breakage) but not yet at 1.0. Current `MAJOR.MINOR` versions are:
57
58 - Version 0.10 was released in February 2026.
59
60 See the [CHANGELOG](https://github.com/rust-random/rand/blob/master/CHANGELOG.md) or [Upgrade Guide](https://rust-random.github.io/book/update.html) for more details.
61
62 ## Crate Features
63
64 Rand is built with these features enabled by default:
65
66 - `std` enables functionality dependent on the `std` lib
67 - `alloc` (implied by `std`) enables functionality requiring an allocator; a
68 significant portion of sequence and distribution functionality requires this
69 - `sys_rng` enables `rand::rngs::SysRng` (uses the [getrandom] crate)
70 - `std_rng` enables `rand::rngs::StdRng` (uses the [chacha20] crate)
71 - `thread_rng` (implies `std`, `std_rng`, `sys_rng`) enables `rand::rngs::ThreadRng` and `rand::rng()`
72
73 Optionally, the following dependencies can be enabled:
74
75 - `chacha` enables `rand::rngs::{ChaCha8Rng, ChaCha12Rng, ChaCha20Rng}` (uses the [chacha20] crate)
76
77 Additionally, these features configure Rand:
78
79 - `simd_support` (experimental) enables sampling of SIMD values (uniformly
80 random SIMD integers and floats). Since `std::simd` is not yet stable this
81 feature requires nightly Rust and may cause build failures.
82 - `unbiased` use unbiased sampling for algorithms supporting this option: Uniform distribution.
83
84 (By default, bias affecting no more than one in 2^48 samples is accepted.)
85
86 Note: enabling this option is expected to affect reproducibility of results.
87
88 ## Portability
89
90 ### Reproducibility
91
92 Achieving reproducible results requires not only deterministic algorithms with fixed inputs but also a commitment to stability of algorithms and some platform-specific considerations. A subset of `rand` does aim to support reproducibility; read more about this in the book: [Portability](https://rust-random.github.io/book/portability.html).
93
94 ### WebAssembly support
95
96 The [WASI](https://github.com/WebAssembly/WASI/tree/main) and Emscripten
97 targets are directly supported. The `wasm32-unknown-unknown` target is not
98 *automatically* supported. To enable support for this target, refer to the
99 [`getrandom` documentation for WebAssembly](https://docs.rs/getrandom/latest/getrandom/#webassembly-support).
100 Alternatively, the `sys_rng` feature may be disabled.
101
102 # License
103
104 Rand is distributed under the terms of both the MIT license and the
105 Apache License (Version 2.0).
106
107 See [LICENSE-APACHE](https://github.com/rust-random/rand/blob/master/LICENSE-APACHE) and [LICENSE-MIT](https://github.com/rust-random/rand/blob/master/LICENSE-MIT), and
108 [COPYRIGHT](https://github.com/rust-random/rand/blob/master/COPYRIGHT) for details.
109
110 [getrandom]: https://crates.io/crates/getrandom
111 [chacha20]: https://crates.io/crates/chacha20