summary refs log tree commit diff
path: root/src/libstd/rand/mod.rs
AgeCommit message (Collapse)AuthorLines
2014-01-07stdtest: Fix all leaked trait importsAlex Crichton-4/+2
2014-01-04Don't allow newtype structs to be dereferenced. #6246Brian Anderson-10/+6
2013-12-29auto merge of #11134 : lucab/rust/lucab/libstd-doc, r=cmrbors-1/+1
Uniform the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index.
2013-12-27std: uniform modules titles for docLuca Bruno-1/+1
This commit uniforms the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index. Signed-off-by: Luca Bruno <lucab@debian.org>
2013-12-26std::rand: remove the `fn main()` from the examples.Huon Wilson-124/+81
2013-12-23std: Fix all code examplesAlex Crichton-7/+8
2013-12-15std: fix spelling in docs.Huon Wilson-1/+1
2013-12-11Make 'self lifetime illegal.Erik Price-3/+3
Also remove all instances of 'self within the codebase. This fixes #10889.
2013-12-08Remove dead codesKiet Tran-0/+1
2013-11-26test: Remove non-procedure uses of `do` from compiletest, libstd tests,Patrick Walton-10/+10
compile-fail tests, run-fail tests, and run-pass tests.
2013-11-22std::rand: move TaskRng off @mut.Huon Wilson-16/+29
Replace with some unsafe code by storing a pointer into TLS-owned heap data.
2013-11-18std::rand: wrappers for floats from [0,1] and (0,1).Huon Wilson-0/+40
Provide `Closed01` and `Open01` that generate directly from the closed/open intervals from 0 to 1, in contrast to the plain impls for f32 and f64 which generate the half-open [0,1). Fixes #7755.
2013-11-01std::rand: share the benchmark counter among the whole module tree.Huon Wilson-11/+11
2013-10-23auto merge of #9810 : huonw/rust/rand3, r=alexcrichtonbors-180/+78
- Adds the `Sample` and `IndependentSample` traits for generating numbers where there are parameters (e.g. a list of elements to draw from, or the mean/variance of a normal distribution). The former takes `&mut self` and the latter takes `&self` (this is the only difference). - Adds proper `Normal` and `Exp`-onential distributions - Adds `Range` which generates `[lo, hi)` generically & properly (via a new trait) replacing the incorrect behaviour of `Rng.gen_integer_range` (this has become `Rng.gen_range` for convenience, it's far more efficient to use `Range` itself) - Move the `Weighted` struct from `std::rand` to `std::rand::distributions` & improve it - optimisations and docs
2013-10-23std::rand: simplify/safe-ify the default Rng.fill_bytes.Huon Wilson-45/+44
The `&[u8]` -> `&[u64]` and `&[u32]` casts were not nice: they ignored alignment requirements and are generally very unsafe.
2013-10-23std::rand: move Weighted to distributions.Huon Wilson-131/+0
A user constructs the WeightedChoice distribution and then samples from it, which allows it to use binary search internally.
2013-10-23std::rand: lengthen the RNG benchmarks.Huon Wilson-8/+20
This makes them more representative, as the `bh.iter` is a smaller percentage of the total time.
2013-10-23std::rand: documentation & references.Huon Wilson-5/+26
Most importantly, links to the papers/references for the core algorithms (the RNG ones & the distribution ones).
2013-10-23std::rand: add distributions::Range for generating [lo, hi).Huon Wilson-37/+33
This reifies the computations required for uniformity done by (the old) `Rng.gen_integer_range` (now Rng.gen_range), so that they can be amortised over many invocations, if it is called in a loop. Also, it makes it correct, but using a trait + impls for each type, rather than trying to coerce `Int` + `u64` to do the right thing. This also makes it more extensible, e.g. big integers could & should implement SampleRange.
2013-10-22Drop the '2' suffix from logging macrosAlex Crichton-5/+5
Who doesn't like a massive renaming?
2013-10-17std: Move size/align functions to std::mem. #2240Brian Anderson-2/+2
2013-10-15use element count in slices, not size in bytesDaniel Micay-5/+9
This allows the indexing bounds check or other comparisons against an element length to avoid a multiplication by the size.
2013-10-10Fix usage of <float> in docsVolker Mische-1/+1
The example for std::rand::random was still using <float>, which got removed from Rust.
2013-10-09option: rewrite the API to use compositionDaniel Micay-1/+1
2013-10-09std::rand: Minor clean-up of comments & add a missing default method.Huon Wilson-2/+5
2013-10-09std::rand: remove seed_task_rng and RUST_SEED.Huon Wilson-76/+9
2013-10-09std::rand: Make Rng.next_u32 non-default, waiting for #7771.Huon Wilson-6/+2
2013-10-09std::rand::reseeding: seed the reseeder in the SeedableRng impl.Huon Wilson-2/+1
This stops us relying on Default here.
2013-10-09Documentation & address minor point.Huon Wilson-4/+8
2013-10-09std::rand: remove `seed`.Huon Wilson-16/+2
This much better handled by directly calling out to `OSRng` where appropriate.
2013-10-09std::rand: documentation additions & fixes.Huon Wilson-7/+23
2013-10-09std::rand: move the Rand impls into a separate file for neatness.Huon Wilson-167/+2
2013-10-09std::rand: add & split some tests.Huon Wilson-0/+20
2013-10-09std::rand: improve the task_rng code.Huon Wilson-19/+116
It now: - can be explicitly seeded from user code (`seed_task_rng`) or from the environment (`RUST_SEED`, a positive integer) - automatically reseeds itself from the OS *unless* it was seeded by either method above - has more documentation
2013-10-09std::rand: Add a trait for seeding RNGs: SeedableRng.Huon Wilson-21/+85
This provides 2 methods: .reseed() and ::from_seed that modify and create respecitively. Implement this trait for the RNGs in the stdlib for which this makes sense.
2013-10-09std::rand: Add ReseedingRng, which will reseed an RNG after it generates a ↵Huon Wilson-0/+1
certain number of bytes. It is an "RNG adaptor" and so any RNG can be wrapped to have this behaviour.
2013-10-09std::rand: add the StdRng wrapper for a blessed RNG.Huon Wilson-7/+54
This is implemented as a wrapper around another RNG. It is designed to allow the actual implementation to be changed without changing the external API (e.g. it currently uses a 64-bit generator on 64- bit platforms, and a 32-bit one on 32-bit platforms; but one could imagine that the IsaacRng may be deprecated later, and having this ability to switch algorithms without having to update the points of use is convenient.) This is the recommended general use RNG.
2013-10-09std::rand: Add OSRng, ReaderRng wrappers around the OS RNG & generic Readers ↵Huon Wilson-29/+93
respectively. The former reads from e.g. /dev/urandom, the latter just wraps any std::rt::io::Reader into an interface that implements Rng. This also adds Rng.fill_bytes for efficient implementations of the above (reading 8 bytes at a time is inefficient when you can read 1000), and removes the dependence on src/rt (i.e. rand_gen_seed) although this last one requires implementing hand-seeding of the XorShiftRng used in the scheduler on Linux/unixes, since OSRng relies on a scheduler existing to be able to read from /dev/urandom.
2013-10-09std::rand: Add an implementation of ISAAC64.Huon Wilson-48/+48
This is 2x faster on 64-bit computers at generating anything larger than 32-bits. It has been verified against the canonical C implementation from the website of the creator of ISAAC64. Also, move `Rng.next` to `Rng.next_u32` and add `Rng.next_u64` to take full advantage of the wider word width; otherwise Isaac64 will always be squeezed down into a u32 wasting half the entropy and offering no advantage over the 32-bit variant.
2013-10-09std::rand: move the Isaac implementation to its own file.Huon Wilson-184/+9
2013-10-05auto merge of #9250 : erickt/rust/num, r=ericktbors-2/+2
This PR solves one of the pain points with c-style enums. Simplifies writing a fn to convert from an int/uint to an enum. It does this through a `#[deriving(FromPrimitive)]` syntax extension. Before this is committed though, we need to discuss if `ToPrimitive`/`FromPrimitive` has the right design (cc #4819). I've changed all the `.to_int()` and `from_int()` style functions to return `Option<int>` so we can handle partial functions. For this PR though only enums and `extra::num::bigint::*` take advantage of returning None for unrepresentable values. In the long run it'd be better if `i64.to_i8()` returned `None` if the value was too large, but I'll save this for a future PR. Closes #3868.
2013-10-04fix some examples in std::rand::Rngflo-l-6/+14
2013-10-02std: Replace num::IntConvertible with {To,From}PrimitiveErick Tryzelaar-2/+2
2013-10-02auto merge of #9665 : alexcrichton/rust/snapshot, r=brsonbors-1/+1
Uses the new snapshots to kill the old `loop` and introduce the new `continue`.
2013-10-01Migrate users of 'loop' to 'continue'Alex Crichton-1/+1
Closes #9467
2013-10-01remove the `float` typeDaniel Micay-14/+7
It is simply defined as `f64` across every platform right now. A use case hasn't been presented for a `float` type defined as the highest precision floating point type implemented in hardware on the platform. Performance-wise, using the smallest precision correct for the use case greatly saves on cache space and allows for fitting more numbers into SSE/AVX registers. If there was a use case, this could be implemented as simply a type alias or a struct thanks to `#[cfg(...)]`. Closes #6592 The mailing list thread, for reference: https://mail.mozilla.org/pipermail/rust-dev/2013-July/004632.html
2013-09-30std: Remove usage of fmt!Alex Crichton-5/+5
2013-09-26Update the compiler to not use printf/printflnAlex Crichton-18/+18
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-28/+28
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-09-23Remove the C(++) ISAAC Rng from the old rt.Huon Wilson-43/+2
This has to leave rust_gen_seed and rng_gen_seed around since they're used to initialise the std::rand RNGs.