summary refs log tree commit diff
path: root/src/libstd/rand/mod.rs
AgeCommit message (Collapse)AuthorLines
2014-09-30Include ChaCha pseudorandom generatorSamuel Neves-1/+1
2014-09-16Fallout from renamingAaron Turon-1/+1
2014-08-26Use temp vars for implicit coercion to ^[T]Nick Cameron-3/+6
2014-08-21auto merge of #16362 : nham/rust/std_rand_pi_example, r=huonwbors-0/+43
Pros: I like this example because it's concise without being trivial. The Monty Hall example code is somewhat lengthy and possibly inaccessible to those unfamiliar with probability. Cons: The Monty Hall example already exists. Do we need another example? Also, this is probably inaccessible to people who don't know basic geometry.
2014-08-21Use unicode pi symbol in pi estimation example. Additional tweaksnham-7/+7
2014-08-21Surround formula in a 'notrust' code blocknham-0/+2
2014-08-18libsyntax: Remove the `use foo = bar` syntax from the language in favorPatrick Walton-2/+2
of `use bar as foo`. Change all uses of `use foo = bar` to `use bar as foo`. Implements RFC #47. Closes #16461. [breaking-change]
2014-08-08Remove the dist function; it is more efficient to compare squared distancesnham-5/+1
2014-08-08Add example of estimating pi using Monte Carlo simulation to std::randnham-0/+45
2014-07-28doc: use //! instead of /*! ... */ in std::randJonas Hietala-167/+163
2014-07-28doc: More efficient Monty Hall simulationJonas Hietala-8/+8
2014-07-28doc: Monty Hall simulation for std::randJonas Hietala-0/+103
A larger example for std::rand
2014-07-18Improve documentation for rand::randomSteve Klabnik-9/+14
This is now linked to in the guide, so I want to make sure it's good. This adds a bit more explanation, and brings usage in line with current good style.
2014-06-30libstd: set baseline stability levels.Aaron Turon-0/+2
Earlier commits have established a baseline of `experimental` stability for all crates under the facade (so their contents are considered experimental within libstd). Since `experimental` is `allow` by default, we should use the same baseline stability for libstd itself. This commit adds `experimental` tags to all of the modules defined in `std`, and `unstable` to `std` itself.
2014-06-29rand: Small fix in parameter namePiotr Jawniak-5/+5
Documentation didn't match with parameter name. Changes name of parameter in docs and function to 'amount'.
2014-06-24librustc: Remove the fallback to `int` from typechecking.Niko Matsakis-14/+14
This breaks a fair amount of code. The typical patterns are: * `for _ in range(0, 10)`: change to `for _ in range(0u, 10)`; * `println!("{}", 3)`: change to `println!("{}", 3i)`; * `[1, 2, 3].len()`: change to `[1i, 2, 3].len()`. RFC #30. Closes #6023. [breaking-change]
2014-06-10Fix unclear wording of commenttheptrk-1/+1
2014-06-06Rename Iterator::len to countAaron Turon-6/+6
This commit carries out the request from issue #14678: > The method `Iterator::len()` is surprising, as all the other uses of > `len()` do not consume the value. `len()` would make more sense to be > called `count()`, but that would collide with the current > `Iterator::count(|T| -> bool) -> unit` method. That method, however, is > a bit redundant, and can be easily replaced with > `iter.filter(|x| x < 5).count()`. > After this change, we could then define the `len()` method > on `iter::ExactSize`. Closes #14678. [breaking-change]
2014-05-30Rename OSRng to OsRngPiotr Jawniak-8/+8
According to Rust's style guide acronyms in type names should be CamelCase. [breaking-change]
2014-05-29std: Recreate a `rand` moduleAlex Crichton-0/+525
This commit shuffles around some of the `rand` code, along with some reorganization. The new state of the world is as follows: * The librand crate now only depends on libcore. This interface is experimental. * The standard library has a new module, `std::rand`. This interface will eventually become stable. Unfortunately, this entailed more of a breaking change than just shuffling some names around. The following breaking changes were made to the rand library: * Rng::gen_vec() was removed. This has been replaced with Rng::gen_iter() which will return an infinite stream of random values. Previous behavior can be regained with `rng.gen_iter().take(n).collect()` * Rng::gen_ascii_str() was removed. This has been replaced with Rng::gen_ascii_chars() which will return an infinite stream of random ascii characters. Similarly to gen_iter(), previous behavior can be emulated with `rng.gen_ascii_chars().take(n).collect()` * {IsaacRng, Isaac64Rng, XorShiftRng}::new() have all been removed. These all relied on being able to use an OSRng for seeding, but this is no longer available in librand (where these types are defined). To retain the same functionality, these types now implement the `Rand` trait so they can be generated with a random seed from another random number generator. This allows the stdlib to use an OSRng to create seeded instances of these RNGs. * Rand implementations for `Box<T>` and `@T` were removed. These seemed to be pretty rare in the codebase, and it allows for librand to not depend on liballoc. Additionally, other pointer types like Rc<T> and Arc<T> were not supported. If this is undesirable, librand can depend on liballoc and regain these implementations. * The WeightedChoice structure is no longer built with a `Vec<Weighted<T>>`, but rather a `&mut [Weighted<T>]`. This means that the WeightedChoice structure now has a lifetime associated with it. * The `sample` method on `Rng` has been moved to a top-level function in the `rand` module due to its dependence on `Vec`. cc #13851 [breaking-change]
2014-03-12std: Move rand to librand.Huon Wilson-906/+0
This functionality is not super-core and so doesn't need to be included in std. It's possible that std may need rand (it does a little bit now, for io::test) in which case the functionality required could be moved to a secret hidden module and reexposed by librand. Unfortunately, using #[deprecated] here is hard: there's too much to mock to make it feasible, since we have to ensure that programs still typecheck to reach the linting phase.
2014-03-04Rename all variables that have uppercase characters in their names to use ↵Palmer Cox-4/+4
only lowercase characters
2014-02-20move extra::test to libtestLiigo Zhuang-1/+2
2014-01-31Introduce marker types for indicating variance and for opting outNiko Matsakis-4/+5
of builtin bounds. Fixes #10834. Fixes #11385. cc #5922.
2014-01-11Remove re-exports of std::io::stdio::{print, println} in the prelude.Brendan Zabarauskas-1/+1
The `print!` and `println!` macros are now the preferred method of printing, and so there is no reason to export the `stdio` functions in the prelude. The functions have also been replaced by their macro counterparts in the tutorial and other documentation so that newcomers don't get confused about what they should be using.
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