@@ -13,13 +13,14 @@ Rand provides utilities to generate random numbers, to convert them to useful
1313types and distributions, and some randomness-related algorithms.
1414
1515The core random number generation traits of Rand live in the [ rand_core] (
16- https://crates.io/crates/rand_core ) crate; this crate is most useful when
17- implementing RNGs.
16+ https://crates.io/crates/rand_core ) crate but are also exposed here; RNG
17+ implementations should prefer to use ` rand_core ` while most other users should
18+ depend on ` rand ` .
1819
1920Documentation:
20- - [ API reference for latest release ] ( https://docs.rs/rand/0.5 )
21- - [ API reference for master branch ] ( https://rust-random.github.io /rand/rand/index.html )
22- - [ Additional documentation (subdir) ] ( doc/README.md )
21+ - [ The Rust Rand Book ] ( https://rust-random.github.io/book/ )
22+ - [ API reference for the latest release ] ( https://docs.rs /rand/ )
23+ - [ API reference for the master branch ] ( https://rust-random.github.io/rand/ )
2324
2425
2526## Usage
@@ -28,78 +29,34 @@ Add this to your `Cargo.toml`:
2829
2930``` toml
3031[dependencies ]
31- rand = " 0.5 "
32+ rand = " 0.6 "
3233```
3334
34- and this to your crate root:
35-
36- ``` rust
37- extern crate rand;
38-
39- use rand :: prelude :: * ;
40-
41- fn main () {
42- // basic usage with random():
43- let x : u8 = random ();
44- println! (" {}" , x );
45-
46- let y = random :: <f64 >();
47- println! (" {}" , y );
48-
49- if random () { // generates a boolean
50- println! (" Heads!" );
51- }
52-
53- // normal usage needs both an RNG and a function to generate the appropriate
54- // type, range, distribution, etc.
55- let mut rng = thread_rng ();
56- if rng . gen () { // random bool
57- let x : f64 = rng . gen (); // random number in range [0, 1)
58- println! (" x is: {}" , x );
59- let ch = rng . gen :: <char >(); // Sometimes you need type annotation
60- println! (" char is: {}" , ch );
61- println! (" Number from 0 to 9: {}" , rng . gen_range (0 , 10 ));
62- }
63- }
64- ```
65-
66- ## Functionality
67-
68- The Rand crate provides:
69-
70- - A convenient to use default RNG, ` thread_rng ` : an automatically seeded,
71- crypto-grade generator stored in thread-local memory.
72- - Pseudo-random number generators: ` StdRng ` , ` SmallRng ` , ` prng ` module.
73- - Functionality for seeding PRNGs: the ` FromEntropy ` trait, and as sources of
74- external randomness ` EntropyRng ` , ` OsRng ` and ` JitterRng ` .
75- - Most content from [ ` rand_core ` ] ( https://crates.io/crates/rand_core )
76- (re-exported): base random number generator traits and error-reporting types.
77- - 'Distributions' producing many different types of random values:
78- - A ` Standard ` distribution for integers, floats, and derived types including
79- tuples, arrays and ` Option `
80- - Unbiased sampling from specified ` Uniform ` ranges.
81- - Sampling from exponential/normal/gamma distributions.
82- - Sampling from binomial/poisson distributions.
83- - ` gen_bool ` aka Bernoulli distribution.
84- - ` seq ` -uence related functionality:
85- - Sampling a subset of elements.
86- - Randomly shuffling a list.
35+ To get started using Rand, see [ The Book] ( https://rust-random.github.io/book/ ) .
8736
8837
8938## Versions
9039
91- Version 0.5 is the latest version and contains many breaking changes.
92- See [ the Upgrade Guide] ( UPDATING.md ) for guidance on updating from previous
93- versions.
40+ The Rand lib is not yet stable, however we are careful to limit breaking changes
41+ and warn via deprecation wherever possible. Patch versions never introduce
42+ breaking changes. The following minor versions are supported:
43+
44+ - Version 0.6 was released in November 2018, redesigning the ` seq ` module,
45+ moving most PRNGs to external crates, and many small changes.
46+ - Version 0.5 was released in May 2018, as a major reorganisation
47+ (introducing ` RngCore ` and ` rand_core ` , and deprecating ` Rand ` and the
48+ previous distribution traits).
49+ - Version 0.4 was released in December 2017, but contained almost no breaking
50+ changes from the 0.3 series.
9451
95- Version 0.4 was released in December 2017. It contains almost no breaking
96- changes since the 0.3 series.
52+ A detailed [ changelog] ( CHANGELOG.md ) is available.
9753
98- For more details, see the [ changelog] ( CHANGELOG.md ) .
54+ When upgrading to the next minor series (especially 0.4 → 0.5), we recommend
55+ reading the [ Upgrade Guide] ( https://rust-random.github.io/book/update.html ) .
9956
10057### Rust version requirements
10158
102- The 0.5 release of Rand requires ** Rustc version 1.22 or greater** .
59+ Since version 0.5, Rand requires ** Rustc version 1.22 or greater** .
10360Rand 0.4 and 0.3 (since approx. June 2017) require Rustc version 1.15 or
10461greater. Subsets of the Rand code may work with older Rust versions, but this
10562is not supported.
@@ -108,6 +65,11 @@ Travis CI always has a build with a pinned version of Rustc matching the oldest
10865supported Rust release. The current policy is that this can be updated in any
10966Rand release if required, but the change must be noted in the changelog.
11067
68+ To avoid bumping the required version unnecessarily, we use a ` build.rs ` script
69+ to auto-detect the compiler version and enable certain features or change code
70+ paths automatically. Since this makes it easy to unintentionally make use of
71+ features requiring a more recent Rust version, we recommend testing with a
72+ pinned version of Rustc if you require compatibility with a specific version.
11173
11274## Crate Features
11375
@@ -137,9 +99,10 @@ functionality depending on `std`:
13799- Since no external entropy is available, it is not possible to create
138100 generators with fresh seeds using the ` FromEntropy ` trait (user must provide
139101 a seed).
140- - Exponential, normal and gamma type distributions are unavailable since ` exp `
102+ - Several non-linear distributions distributions are unavailable since ` exp `
141103 and ` log ` functions are not provided in ` core ` .
142- - The ` seq ` -uence module is unavailable, as it requires ` Vec ` .
104+ - Large parts of the ` seq ` -uence module are unavailable, unless the ` alloc `
105+ feature is used (several APIs and many implementations require ` Vec ` ).
143106
144107
145108# License
0 commit comments