Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crate refactor #161

Closed
wants to merge 302 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
302 commits
Select commit Hold shift + click to select a range
21de6ae
Add no_std support by conditionally disabling many features
dhardy Aug 6, 2017
212e04e
Integer ranges: reject fewer samples
dhardy Aug 6, 2017
e386895
Add SimpleRand (example) and improve Rand doc
dhardy Aug 7, 2017
88f73e0
Fix Rand doc and rename dist var to distr
dhardy Aug 7, 2017
69681f6
Merge remote-tracking branch 'origin/master'
dhardy Aug 7, 2017
3a4ace5
Fix benchmarks; add ChaCha and LogNormal benchmarks
dhardy Aug 11, 2017
96c2a42
Revise benchmarks into three separate ones; add comparators
dhardy Aug 11, 2017
dc8c1f4
Benches: add missing file from prev. commit
dhardy Aug 11, 2017
21a4375
Move thread_local stuff to new module. Tweaks for no_std.
dhardy Aug 11, 2017
404e282
Require Rng: Debug
dhardy Aug 14, 2017
68bb549
Make thread_rng use OsRng by default and allow override
dhardy Aug 14, 2017
d2b9f8e
Add ConstRng type; improve set_thread_rng doc
dhardy Aug 14, 2017
adbbd9d
Replace ConstantRng in uniform tests with ConstRng
dhardy Aug 14, 2017
2511b27
Add fn new() -> Self for Rngs; remove weak_rng()
dhardy Aug 14, 2017
cde9f58
Add Sample trait
dhardy Aug 15, 2017
28972a1
Add Sample::iter wrapper; add AsciiWordChar distribution
dhardy Aug 15, 2017
fe990d9
Update Sample doc
dhardy Aug 15, 2017
a8b2871
Add size_hint() to Iterator impls
dhardy Aug 15, 2017
57efe7e
Remove distributions::range*::range functions, rename new_range → range
dhardy Aug 16, 2017
697b83e
Add no_std build test to travis; fix no_std build
dhardy Aug 17, 2017
ecc8a38
Add 128-bit integer support to range types
dhardy Aug 17, 2017
831553c
Add range benchmarks
dhardy Aug 17, 2017
18e8dab
Remove unnecessary mutability
dhardy Aug 17, 2017
e73622f
Update travis and appveyor: require Rust 1.18, don't test rand-derive
dhardy Aug 17, 2017
de24228
Remove next_u8 and next_u16 functions from Rng
dhardy Aug 21, 2017
cca68bb
Remove Rng: Debug requirement
dhardy Aug 21, 2017
2a59377
Add CryptoError; make RNG::new return Result<Self, CryptoError>; rena…
dhardy Aug 21, 2017
a3f5bf1
Remove useless impl
dhardy Aug 26, 2017
1f1db33
range2: enable Range::new(low, high); remove convenience function
dhardy Aug 30, 2017
db93780
Fix benchmarks
dhardy Sep 1, 2017
b7edfdb
Higher precision for floats in range [0,1)
Sep 3, 2017
fadc260
Make ranges preserve precision
Sep 3, 2017
3c800b1
Use optimized float conversions in ziggurat
Sep 3, 2017
ca7b10f
Move `FloatConversions` to a new module
Sep 3, 2017
1dbf23d
Add a few extra benchmarks
Sep 3, 2017
ac33b28
Add a changelog
Sep 3, 2017
ed637de
Merge pull request #3 from pitdicker/changelog
dhardy Sep 3, 2017
e8b06db
Merge pull request #1 from pitdicker/master
dhardy Sep 3, 2017
a2b2196
Fix no_std build
dhardy Sep 3, 2017
eb162fe
Remove SeedableRng impl for StdRng
dhardy Sep 3, 2017
d6f4831
Rng: fix to LE, fix missing next_u128 in wrappers, improve fill_bytes…
dhardy Sep 3, 2017
0ca5c4e
no_std: fix "unused import" warnings
dhardy Sep 3, 2017
e4a7fcd
Merge remote-tracking branch 'origin'
dhardy Sep 4, 2017
04e326d
Include gen_bytes_* generator benchmarks; use macros
dhardy Sep 4, 2017
0cd5539
Replace fill_bytes code with @newpavlov's code
dhardy Sep 4, 2017
e177594
Use macro in distributions bench to reduce source size
dhardy Sep 4, 2017
81821a6
Move open/closed/uniform 01 benchs from misc to distributions; use bl…
dhardy Sep 4, 2017
2e26002
Simplify OsRng impls: only impl next_* once & use minimal ReadRng impl
dhardy Sep 4, 2017
0fc565e
misc benchmark: clean up unneeded imports
dhardy Sep 4, 2017
fa4eb5b
Add FromRng and NewRng
dhardy Sep 4, 2017
31f964e
Add benchmarks for ranges of i8, i16 and i32
Sep 7, 2017
8906c29
Optimise fill_bytes impls for ChaCha and Isaac RNGs
dhardy Sep 8, 2017
0a97209
Rename CryptoError → Error; add Result<T> using the prior error type
dhardy Sep 10, 2017
a07bcdf
Replace fill_bytes with try_fill returning Result<()>
dhardy Sep 10, 2017
07b222b
Move Rng and other core bits to rand_core crate
dhardy Sep 10, 2017
b8873f7
Rename FromRng → SeedFromRng and NewRng → NewSeeded
dhardy Sep 11, 2017
10f794f
Add rand_core/README.md
dhardy Sep 11, 2017
ec29f80
Fix i128_support for sub crate
dhardy Sep 11, 2017
ad973f1
Add notes on testing to README
dhardy Sep 11, 2017
95a16c3
Replace ReseedWithDefault with ReseedWithNew using NewSeeded
dhardy Sep 11, 2017
ec7e6bf
Split isaac into 3 modules
Sep 11, 2017
4747665
Refactor isaac.rs
Sep 11, 2017
90c094d
Remove set_thread_rng/set_new_thread_rng; revert thread_rng to reseed…
dhardy Sep 12, 2017
0ee54b1
Add MockAddRng to rand_core; remove all other mock RNGs
dhardy Sep 12, 2017
dd1241a
Add rand_core::impls module; remove all default impls of Rng functions
dhardy Sep 12, 2017
14d0561
Add some extra documentation
Sep 11, 2017
2cb9acd
Fix OsRng for other platforms (hopefully)
dhardy Sep 13, 2017
37faeb5
Merge remote-tracking branch 'pitdicker/isaac-rewrite'
dhardy Sep 13, 2017
da1ff46
rand_core: improve a few comments/doc
dhardy Sep 14, 2017
67b22bd
rand_core: update Cargo.toml
dhardy Sep 14, 2017
ec70309
rand_core: add impl<R: Rng> Rng for &mut R
dhardy Sep 14, 2017
d8b8474
Allow sampling from a closed integer range
Sep 7, 2017
7edd06b
Remove range.rs
Sep 30, 2017
96503f7
Replace range with range2
Sep 30, 2017
86de12b
Remove `reseed` from `SeedableRng`
Sep 24, 2017
97ab178
Merge pull request #2 from pitdicker/range_int
dhardy Oct 14, 2017
dfdf89c
Merge pull request #6 from pitdicker/no_reseeding
dhardy Oct 16, 2017
e3784ab
Fix FlatMap::size_hint (thanks @bluss)
dhardy Oct 18, 2017
250aa65
Merge remote-tracking branch 'origin/master'
dhardy Oct 18, 2017
496c0fc
Fix i128_support in range.rs
pitdicker Oct 19, 2017
a6528a3
Add initialization benchmarks
pitdicker Oct 19, 2017
08ac750
Clean up ISAAC tests
pitdicker Oct 19, 2017
2e714f2
Remove `range2` from benchmarks
pitdicker Oct 19, 2017
adcd8e5
Add `new_from_u64` to `IsaacRng` and `Isaac64Rng`
pitdicker Oct 19, 2017
849f01a
Add Error type and ErrorKind
pitdicker Oct 19, 2017
dbbe143
Add back `fill_bytes`
pitdicker Oct 19, 2017
019d9c1
Improve error handeling of `ReadRng`
pitdicker Oct 19, 2017
44ef65f
Remove default implementation from `try_fill`
pitdicker Oct 20, 2017
a4e9885
Merge pull request #7 from pitdicker/error_enum
dhardy Oct 21, 2017
d511022
Merge pull request #14 from pitdicker/fix_i128_support
dhardy Oct 21, 2017
130b64c
Simplify isaac init code
pitdicker Oct 20, 2017
58350a9
Merge branch 'master' into isaac_init
pitdicker Oct 21, 2017
bf53631
Merge pull request #5 from pitdicker/isaac_init
dhardy Oct 21, 2017
ebec6c7
rand-core: add CryptoRng trait
dhardy Oct 21, 2017
6712a3a
Remove `Copy` trait from ChaCha
pitdicker Oct 21, 2017
e513aaa
Custom Debug implementation for ChaCha and Xorshift
pitdicker Oct 21, 2017
fdf4017
Implement Debug for TreadRng
pitdicker Oct 21, 2017
37f7450
Remove Debug bound from ReadRng
pitdicker Oct 21, 2017
b5556c6
Make `OsRng` Debug use `imp::OsRng` Debug
pitdicker Oct 21, 2017
6edac27
Merge pull request #16 from pitdicker/common_traits
dhardy Oct 21, 2017
47bdc03
Fix unaligned cast in `impl_uint_from_fill`
pitdicker Oct 22, 2017
b9d9987
Drop support for PNaCL
pitdicker Oct 22, 2017
32e325c
from_rng: remove explicit ref; rely on impl rule
dhardy Oct 23, 2017
2679dbd
Merge remote-tracking branch 'dhardy/master'
dhardy Oct 23, 2017
c4eb96c
Move mock module from rand_core to rand
dhardy Oct 23, 2017
819a282
Merge pull request #19 from pitdicker/drop_pnacl
dhardy Oct 28, 2017
0b1ac0f
Use fill_bytes(..) instead of try_fill(..).unwrap()
dhardy Oct 30, 2017
9a4e2e7
Merge pull request #20 from pitdicker/fill_from_next
dhardy Oct 31, 2017
07e1d58
Implement `JitterRng`, based on `jitterentropy-library`.
pitdicker Oct 30, 2017
6e40910
Relicensing permission
pitdicker Nov 2, 2017
8ff9394
Revise error type (copy from error_details branch)
dhardy Nov 8, 2017
f4a43f7
Revise handling in os and read modules
dhardy Nov 8, 2017
442caee
Reseeding: handle/forward failures from source RNG
dhardy Nov 8, 2017
49e9bb0
Provide statistics function
pitdicker Nov 4, 2017
ed358de
Make the number of entropy colelction rounds variable
pitdicker Nov 8, 2017
c57aa1a
Address review comments
pitdicker Nov 8, 2017
bd60937
Merge pull request #34 from dhardy/err2
dhardy Nov 9, 2017
908fda4
Fix: Error::new(_, _, None) was not usable
dhardy Nov 9, 2017
e6b224d
Merge branch 'master' into reseeding
dhardy Nov 9, 2017
6302f53
Fix Debug/Clone support of mock and reseeding RNGs as per #13
dhardy Nov 9, 2017
89f0430
Reseeding: cleaner code
dhardy Nov 9, 2017
fdb09d4
Update travis build scripts
dhardy Nov 10, 2017
3bf4680
Implicit error handling (#25)
dhardy Nov 9, 2017
585b738
OsRng: return NotReady if not initialised yet (linux getrandom)
dhardy Nov 9, 2017
508f22c
Implicit handling: use local counter
dhardy Nov 10, 2017
4b8371f
Reseeding: limit retries for transient errors
dhardy Nov 10, 2017
3b7666c
Merge branch 'master' into reseeding
dhardy Nov 10, 2017
d387570
Split gen_usize_* benchmarks into gen_u32_* and gen_u64_*
dhardy Nov 10, 2017
6e9c1ab
Rejig ChaCha and Isaac construction tests
dhardy Nov 10, 2017
ae365ef
Add true_bytes tests for ChaCha and Isaac; fix 2 bugs in fill_bytes i…
dhardy Nov 10, 2017
fd2660b
Isaac64: add test for true 32-bit values
dhardy Nov 10, 2017
ab79378
Merge pull request #42 from dhardy/true_bytes
dhardy Nov 10, 2017
c8a8f86
Merge pull request #35 from dhardy/reseeding
dhardy Nov 10, 2017
d67864a
Add `rand_core::impl::fill_via_u*_chunks`
pitdicker Nov 10, 2017
d7b014c
Convert ChaCha to use `fill_via_u32_chunks`
pitdicker Nov 11, 2017
f92a347
Fill `isaac` backwards, and use `fill_via_u32_chunks`
pitdicker Nov 11, 2017
707c3e1
Fill `isaac64` backwards, and use `fill_via_u32_chunks`
pitdicker Nov 11, 2017
415ef6f
Improve performance of `isaac64::next_u32`.
pitdicker Nov 11, 2017
c218f7a
Add CI based on `trust`
pitdicker Nov 10, 2017
701679c
Merge pull request #44 from pitdicker/ci
dhardy Nov 11, 2017
0bdb1c3
Remove complex indexing, use a bool.
pitdicker Nov 11, 2017
5f4bedf
Add test for alternating between `next_u64` and `next_u32`
pitdicker Nov 11, 2017
69d940f
Improve documentation
pitdicker Nov 11, 2017
fe822c0
Merge pull request #45 from pitdicker/isaac_optim
dhardy Nov 11, 2017
08dc010
Merge remote-tracking branch 'upstream/master' into jitter_rng
pitdicker Nov 11, 2017
500b574
Implicit handling: max wait 1 minute if not ready; extra doc
dhardy Nov 11, 2017
7f3c9b0
Fix `no_std` errors
pitdicker Nov 11, 2017
d92451a
JitterRng: reduce error-handling code
dhardy Nov 11, 2017
14136e7
Fix `no_std` errors
pitdicker Nov 11, 2017
8971695
Travis: test on a bare-metal target
dhardy Nov 11, 2017
6701189
Crate dependencies: set default-features = false
dhardy Nov 11, 2017
2486226
Include ziggurat_tables.py
pitdicker Nov 11, 2017
35f0cd7
Cargo: make std feature optional and transitive
dhardy Nov 13, 2017
32ea1d2
Travis: adjust build targets
dhardy Nov 13, 2017
026b50e
OsRng: squelch warnings about ununsed code on some targets
dhardy Nov 13, 2017
c74cb3f
Travis: fix build script for no_std
dhardy Nov 13, 2017
065baa7
Move ziggurat_tables.py out of source tree
dhardy Nov 13, 2017
96ec26c
Merge branch 'err_implicit_handling'
dhardy Nov 13, 2017
8b62a03
Merge branch 'master' into no_std
dhardy Nov 13, 2017
7adefa0
Merge most of branch 'no_std', minus no_std build
dhardy Nov 13, 2017
82e18c6
Enable all thumb* targets
dhardy Nov 13, 2017
137fe01
Use nightly for bare-metal targets
dhardy Nov 13, 2017
ae45ffe
Merge branch 'master' into jitter_rng
dhardy Nov 14, 2017
fe3486b
Merge remote-tracking branch 'pitdicker/jitter_rng' into jitter_rng
dhardy Nov 14, 2017
afce69d
Fix link to documentaion
vks Nov 14, 2017
4fff5af
Make libc dep optional (use with std only)
dhardy Nov 14, 2017
1e84e50
Add cat_rng tool
dhardy Nov 15, 2017
38e5d8d
JitterRng: reduce FACTOR to 3 to avoid overflow
dhardy Nov 14, 2017
aafcba8
JitterRng: allow users to set number of rounds; cache timer test result
dhardy Nov 15, 2017
82d9731
Merge branch 'master' into jitter_rng
dhardy Nov 17, 2017
9d8021b
JitterRng: fix benchmark
dhardy Nov 17, 2017
b4746c8
NewSeeded: use JitterRng fallback
dhardy Nov 17, 2017
95c0b35
Merge pull request #51 from vks/patch-1
dhardy Nov 17, 2017
bd4c793
CI: move ci to utils/ci
dhardy Nov 17, 2017
cf211f9
CI: show status of my branch in readme
dhardy Nov 17, 2017
2821328
Cargo: don't use libc at all if no_std
dhardy Nov 17, 2017
53ab77e
JitterRng: remove unused stuff for no_std
dhardy Nov 17, 2017
8be4f63
Cargo: do not use std by default in rand_core
dhardy Nov 17, 2017
a41c055
Merge branch 'master' into no_std
dhardy Nov 17, 2017
eca5e36
JitterRng::timer_stats: do not run example
dhardy Nov 17, 2017
bcde73a
Merge branch 'master' into no_std
dhardy Nov 17, 2017
e472682
Workaround #55: don't run nightly tests on darwin
dhardy Nov 19, 2017
442e7a7
Disable FreeBSD nightly too
dhardy Nov 20, 2017
e7335be
Merge pull request #56 from dhardy/jitter-bench-darwin
dhardy Nov 20, 2017
0ccaa6b
Fix `JitterRng` on Mac OS
pitdicker Nov 20, 2017
03ff2d6
Merge pull request #57 from pitdicker/jitterrng_apple
dhardy Nov 21, 2017
2a38131
Merge branch 'master' into new_seeded
dhardy Nov 21, 2017
17e08de
Workaround #55: don't run nightly tests on darwin
dhardy Nov 19, 2017
05d0449
Disable FreeBSD nightly too
dhardy Nov 20, 2017
db99fda
Fix `JitterRng` on Mac OS
pitdicker Nov 20, 2017
8b0d1ad
Merge pull request #54 from dhardy/new_seeded
dhardy Nov 21, 2017
cc437de
MockAddRng: remove templating
dhardy Nov 24, 2017
e621639
SeaHash, seeding via hash, SeadableRng::Seed
dhardy Nov 24, 2017
e87b0a7
Fix JitterRng on Windows
pitdicker Nov 25, 2017
9eca335
Merge pull request #63 from pitdicker/jitter_windows
dhardy Nov 25, 2017
7897515
Merge commit 'e621639834e23bc1b4c8454d58cd90fb2f8da27e'
dhardy Dec 1, 2017
697d88a
Remove from_hashable code
dhardy Dec 1, 2017
c03c211
Merge rust-lang-nursery/master into dhardy/master
dhardy Dec 3, 2017
eae85e2
Rename new_with_cause → with_cause
dhardy Dec 4, 2017
c826587
Benchmarks: add f32 open/closed/half-open distr tests
dhardy Dec 5, 2017
b8fb05c
Merge branch 'master' into dh-master
dhardy Dec 7, 2017
51a27e1
Add alloc feature; enables seq code
dhardy Dec 8, 2017
43267f7
Use a sign test for bools
pitdicker Dec 7, 2017
c8c720e
Ignore the 3 least significant bits for the ziggurat layer
pitdicker Dec 7, 2017
3f22ddd
Use widening multiply instead of modulus in RangeInt
pitdicker Dec 10, 2017
68edc9f
Add a few extra distr benchmarks
pitdicker Dec 11, 2017
173c2b4
Benchmark constructing and sampling from a range
pitdicker Dec 11, 2017
51cc0ed
Merge pull request #68 from pitdicker/avoid_low_bits
dhardy Dec 11, 2017
5e492e5
Merge branch 'master' into dh-master
dhardy Dec 11, 2017
888c5d2
Cherry-pick 243e1ea: Add rand_core::le module, switch SeedableRng::Se…
dhardy Nov 27, 2017
ada83bd
Fix rand_core::le test on convert_slice_64
dhardy Dec 11, 2017
5a7dbb0
Add sample_single to Range
pitdicker Dec 11, 2017
4d832a7
Use mask to reduce range in ascii_word_char
pitdicker Dec 12, 2017
4e79c06
Improve documentation of range module
dhardy Dec 12, 2017
259281e
Select "SimpleRand" over generic "Rand" for backwards compatibility
dhardy Dec 12, 2017
1913e08
Add a default implementation for sample_single
pitdicker Dec 13, 2017
6249973
Merge remote-tracking branch 'upstream/master' into range_single_sample
pitdicker Dec 13, 2017
4ebd21f
Merge pull request #69 from pitdicker/range_single_sample
dhardy Dec 13, 2017
af4f3f9
Fix tests: use Sample not Rand
dhardy Dec 14, 2017
9d236da
Replace uniform, codepoint and ascii_word_char functions with distrib…
dhardy Dec 14, 2017
e90e9eb
Merge changes from #69 (sample_single)
dhardy Dec 14, 2017
fe40af0
Don't assume usize is 4 or 8 bytes
dhardy Dec 14, 2017
de17011
Merge pull request #71 from dhardy/simple-rand
dhardy Dec 14, 2017
e18d489
Add HC-128 RNG
pitdicker Dec 14, 2017
0ac7b86
impl CryptoRng for Hc128Rng
pitdicker Dec 14, 2017
b9f7123
Add test for `fill_bytes`
pitdicker Dec 14, 2017
5741e16
Rename AsciiWordChar to AlphanumericChar
pitdicker Dec 16, 2017
a0deb78
Optimize Codepoint distribution
pitdicker Dec 16, 2017
e3c8ca1
Merge pull request #75 from pitdicker/char_distrs
dhardy Dec 18, 2017
4058522
Merge branch 'master' into dh-master
dhardy Dec 19, 2017
f58b2f1
Merge: reorder use/mod declarations
dhardy Dec 19, 2017
4e088f1
Fix comment
dhardy Dec 19, 2017
729644c
Remove log dependency; make i128_support transitive
dhardy Dec 20, 2017
eaeee11
Merge pull request #74 from pitdicker/hc-128
dhardy Dec 21, 2017
4f1deb7
Restrict Seed type
dhardy Dec 21, 2017
92831f3
Replace `convert_slice_{32,64}` with `read_u{32,64}_into`
pitdicker Dec 21, 2017
cc6da7a
Fold from_rng into SeedableRng
pitdicker Dec 23, 2017
5d9acdc
Merge pull request #77 from pitdicker/blockrng
dhardy Dec 27, 2017
e9359ac
Fix sealed implementation of SeedRestriction to prevent extension
dhardy Dec 27, 2017
945e8ff
Make u128 range use widening multiply
pitdicker Dec 28, 2017
4ea098b
Restrict the seed type to a few more array sizes
pitdicker Dec 29, 2017
45ace88
Merge pull request #80 from pitdicker/seed_sizes
dhardy Dec 31, 2017
1f9ce3a
Merge pull request #79 from pitdicker/range_128
dhardy Dec 31, 2017
402e673
Add benchmarks for `ReseedingRng`
pitdicker Dec 16, 2017
4d10328
Improve performance of `ReseedingRng`
pitdicker Dec 16, 2017
07717bc
Simplify reseeding erro logic
pitdicker Dec 31, 2017
8990da2
Add rand_core::le::test_read unit test
dhardy Nov 27, 2017
14f02a2
Benchmark reseeding HC-128 instead of Xorshift
pitdicker Dec 31, 2017
d5d9c75
Merge pull request #76 from pitdicker/reseeding_perf
dhardy Jan 1, 2018
a4ff5d7
Merge in upstream
dhardy Jan 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,5 @@ nightly = ["i128_support"]
[dependencies]
libc = "0.2"

[dev-dependencies]
log = "0.3.0"

[workspace]
members = ["rand-derive"]

[target.'cfg(target_os = "fuchsia")'.dependencies]
magenta = "^0.1.1"
53 changes: 16 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,57 +25,36 @@ extern crate rand;

## Examples

There is built-in support for a random number generator (RNG) associated with each thread stored in thread-local storage. This RNG can be accessed via thread_rng, or used implicitly via random. This RNG is normally randomly seeded from an operating-system source of randomness, e.g. /dev/urandom on Unix systems, and will automatically reseed itself from this source after generating 32 KiB of random data.
There is built-in support for a random number generator (RNG) associated with
each thread stored in thread-local storage. This RNG can be accessed via
thread_rng.

```rust
let tuple = rand::random::<(f64, char)>();
println!("{:?}", tuple)
use rand::thread_rng;

let x: u32 = thread_rng().next_u32();
println!("{}", u32)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

println!("{}", x)

```

```rust
use rand::dist::{uniform};
use rand::Rng;

let mut rng = rand::thread_rng();
if rng.gen() { // random bool
println!("i32: {}, u32: {}", rng.gen::<i32>(), rng.gen::<u32>())
if uniform(&mut rng) { // random bool
let x: i32 = uniform(&mut rng);
let y: u32 = uniform(&mut rng);
println!("i32: {}, u32: {}", x, y);
}
```

It is also possible to use other RNG types, which have a similar interface. The following uses the "ChaCha" algorithm instead of the default.

```rust
use rand::{Rng, ChaChaRng};

let mut rng = rand::ChaChaRng::new_unseeded();
println!("i32: {}, u32: {}", rng.gen::<i32>(), rng.gen::<u32>())
```

# `derive(Rand)`

You can derive the `Rand` trait for your custom type via the `#[derive(Rand)]`
directive. To use this first add this to your Cargo.toml:

```toml
rand = "0.3"
rand-derive = "0.3"
```

Next in your crate:
It is also possible to use other generators types, which have a similar interface. The following uses the "ChaCha" algorithm instead of the default.

```rust
extern crate rand;
#[macro_use]
extern crate rand_derive;

#[derive(Rand, Debug)]
struct MyStruct {
a: i32,
b: u32,
}
use rand::{thread_rng, ChaChaRng, dist};

fn main() {
println!("{:?}", rand::random::<MyStruct>());
}
let mut rng = ChaChaRng::new_from_rng(&mut thread_rng());
println!("random between 0-9: {}", dist::range(0, 10, &mut rng));
```


Expand Down
22 changes: 12 additions & 10 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,39 @@ mod distributions;

use std::mem::size_of;
use test::{black_box, Bencher};
use rand::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng};
use rand::{OsRng, sample, weak_rng};
use rand::{Rng, StdRng, OsRng, weak_rng};
use rand::prng::{XorShiftRng, IsaacRng, Isaac64Rng};
use rand::{sample, Shuffle};
use rand::dist::uniform;

#[bench]
fn rand_xorshift(b: &mut Bencher) {
let mut rng: XorShiftRng = OsRng::new().unwrap().gen();
let mut rng = XorShiftRng::new_from_rng(&mut OsRng::new().unwrap());
b.iter(|| {
for _ in 0..RAND_BENCH_N {
black_box(rng.gen::<usize>());
black_box(uniform::<usize, _>(&mut rng));
}
});
b.bytes = size_of::<usize>() as u64 * RAND_BENCH_N;
}

#[bench]
fn rand_isaac(b: &mut Bencher) {
let mut rng: IsaacRng = OsRng::new().unwrap().gen();
let mut rng = IsaacRng::new_from_rng(&mut OsRng::new().unwrap());
b.iter(|| {
for _ in 0..RAND_BENCH_N {
black_box(rng.gen::<usize>());
black_box(uniform::<usize, _>(&mut rng));
}
});
b.bytes = size_of::<usize>() as u64 * RAND_BENCH_N;
}

#[bench]
fn rand_isaac64(b: &mut Bencher) {
let mut rng: Isaac64Rng = OsRng::new().unwrap().gen();
let mut rng = Isaac64Rng::new_from_rng(&mut OsRng::new().unwrap());
b.iter(|| {
for _ in 0..RAND_BENCH_N {
black_box(rng.gen::<usize>());
black_box(uniform::<usize, _>(&mut rng));
}
});
b.bytes = size_of::<usize>() as u64 * RAND_BENCH_N;
Expand All @@ -50,7 +52,7 @@ fn rand_std(b: &mut Bencher) {
let mut rng = StdRng::new().unwrap();
b.iter(|| {
for _ in 0..RAND_BENCH_N {
black_box(rng.gen::<usize>());
black_box(uniform::<usize, _>(&mut rng));
}
});
b.bytes = size_of::<usize>() as u64 * RAND_BENCH_N;
Expand Down Expand Up @@ -83,7 +85,7 @@ fn rand_shuffle_100(b: &mut Bencher) {
let mut rng = weak_rng();
let x : &mut [usize] = &mut [1; 100];
b.iter(|| {
rng.shuffle(x);
x.shuffle(&mut rng);
})
}

Expand Down
6 changes: 3 additions & 3 deletions benches/distributions/exponential.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::mem::size_of;
use test::Bencher;
use rand;
use rand::distributions::exponential::Exp;
use rand::distributions::Sample;
use rand::dist::exponential::Exp;
use rand::dist::Distribution;

#[bench]
fn rand_exp(b: &mut Bencher) {
let mut rng = rand::weak_rng();
let mut exp = Exp::new(2.71828 * 3.14159);
let exp = Exp::new(2.71828 * 3.14159);

b.iter(|| {
for _ in 0..::RAND_BENCH_N {
Expand Down
8 changes: 4 additions & 4 deletions benches/distributions/gamma.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::mem::size_of;
use test::Bencher;
use rand;
use rand::distributions::IndependentSample;
use rand::distributions::gamma::Gamma;
use rand::dist::Distribution;
use rand::dist::gamma::Gamma;

#[bench]
fn bench_gamma_large_shape(b: &mut Bencher) {
Expand All @@ -11,7 +11,7 @@ fn bench_gamma_large_shape(b: &mut Bencher) {

b.iter(|| {
for _ in 0..::RAND_BENCH_N {
gamma.ind_sample(&mut rng);
gamma.sample(&mut rng);
}
});
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
Expand All @@ -24,7 +24,7 @@ fn bench_gamma_small_shape(b: &mut Bencher) {

b.iter(|| {
for _ in 0..::RAND_BENCH_N {
gamma.ind_sample(&mut rng);
gamma.sample(&mut rng);
}
});
b.bytes = size_of::<f64>() as u64 * ::RAND_BENCH_N;
Expand Down
6 changes: 3 additions & 3 deletions benches/distributions/normal.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::mem::size_of;
use test::Bencher;
use rand;
use rand::distributions::Sample;
use rand::distributions::normal::Normal;
use rand::dist::Distribution;
use rand::dist::normal::Normal;

#[bench]
fn rand_normal(b: &mut Bencher) {
let mut rng = rand::weak_rng();
let mut normal = Normal::new(-2.71828, 3.14159);
let normal = Normal::new(-2.71828, 3.14159);

b.iter(|| {
for _ in 0..::RAND_BENCH_N {
Expand Down
23 changes: 0 additions & 23 deletions rand-derive/Cargo.toml

This file was deleted.

51 changes: 0 additions & 51 deletions rand-derive/README.md

This file was deleted.

106 changes: 0 additions & 106 deletions rand-derive/src/lib.rs

This file was deleted.

Loading