summary refs log tree commit diff
path: root/src/libstd/rand
AgeCommit message (Collapse)AuthorLines
2014-01-07stdtest: Fix all leaked trait importsAlex Crichton-31/+25
2014-01-07Fix remaining cases of leaking importsAlex Crichton-0/+3
2014-01-07std: Fill in all missing importsAlex Crichton-5/+14
Fallout from the previous commits
2014-01-06Remove some unnecessary type castsFlorian Hahn-1/+1
Conflicts: src/librustc/middle/lint.rs
2014-01-04Don't allow newtype structs to be dereferenced. #6246Brian Anderson-27/+28
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-174/+113
2013-12-23std: Fix all code examplesAlex Crichton-13/+14
2013-12-20std: silence warnings when compiling test.Huon Wilson-0/+3
2013-12-19std::vec: remove .as_muf_buf, replaced by .as_mut_ptr & .len.Huon Wilson-3/+1
2013-12-16Fallout of rewriting std::commAlex Crichton-7/+3
2013-12-15auto merge of #10984 : huonw/rust/clean-raw, r=cmrbors-6/+6
See commits for details.
2013-12-15std::vec: convert to(_mut)_ptr to as_... methods on &[] and &mut [].Huon Wilson-2/+2
2013-12-15std::vec: move pointless `raw::get` and `unsafe_get` functions.Huon Wilson-4/+4
This can easily be written as `(*v.unsafe_ref(i)).clone()`, or just `*v.unsafe_ref(i)` for primitive types like `i32` (the common case).
2013-12-15std: fix spelling in docs.Huon Wilson-4/+4
2013-12-11Make 'self lifetime illegal.Erik Price-9/+9
Also remove all instances of 'self within the codebase. This fixes #10889.
2013-12-09auto merge of #10859 : huonw/rust/helper-dists, r=cmrbors-246/+568
This moves `std::rand::distribitions::{Normal, StandardNormal}` to `...::distributions::normal`, reexporting `Normal` from `distributions` (and similarly for `Exp` and Exp1`), and adds: - Log-normal - Chi-squared - F - Student T all of which are implemented in C++11's random library. Tests in https://github.com/huonw/random-tests/commit/0424b8aded5e608ae386c1f917934a726d9cac6a. Note that these are approximately half documentation & half implementation (of which a significant portion is boilerplate `}`'s and so on).
2013-12-08std::rand: implement the student t distribution.Huon Wilson-1/+52
2013-12-08std::rand: implement the F distribution.Huon Wilson-1/+60
2013-12-08std::rand: implement the chi-squared distribution.Huon Wilson-2/+99
2013-12-08Remove dead codesKiet Tran-0/+1
2013-12-07std::rand: implement the log-normal distribution.Huon Wilson-2/+58
2013-12-07std::rand: move normal and exponential to their own file.Huon Wilson-244/+303
2013-12-04Revert "libstd: Change `Path::new` to `Path::init`."Kevin Ballard-1/+1
This reverts commit c54427ddfbbab41a39d14f2b1dc4f080cbc2d41b. Leave the #[ignores] in that were added to rustpkg tests. Conflicts: src/librustc/driver/driver.rs src/librustc/metadata/creader.rs
2013-11-29libstd: Change `Path::new` to `Path::init`.Patrick Walton-1/+1
2013-11-26libstd: Fix Win32 and other bustage.Patrick Walton-2/+2
2013-11-26test: Remove non-procedure uses of `do` from compiletest, libstd tests,Patrick Walton-18/+18
compile-fail tests, run-fail tests, and run-pass tests.
2013-11-26libstd: Remove all non-`proc` uses of `do` from libstdPatrick Walton-5/+5
2013-11-26librustc: Remove remaining uses of `&fn()` in favor of `||`.Patrick Walton-6/+8
2013-11-24auto merge of #10603 : alexcrichton/rust/no-linked-failure, r=brsonbors-1/+1
The reasons for doing this are: * The model on which linked failure is based is inherently complex * The implementation is also very complex, and there are few remaining who fully understand the implementation * There are existing race conditions in the core context switching function of the scheduler, and possibly others. * It's unclear whether this model of linked failure maps well to a 1:1 threading model Linked failure is often a desired aspect of tasks, but we would like to take a much more conservative approach in re-implementing linked failure if at all. Closes #8674 Closes #8318 Closes #8863
2013-11-24Remove linked failure from the runtimeAlex Crichton-1/+1
The reasons for doing this are: * The model on which linked failure is based is inherently complex * The implementation is also very complex, and there are few remaining who fully understand the implementation * There are existing race conditions in the core context switching function of the scheduler, and possibly others. * It's unclear whether this model of linked failure maps well to a 1:1 threading model Linked failure is often a desired aspect of tasks, but we would like to take a much more conservative approach in re-implementing linked failure if at all. Closes #8674 Closes #8318 Closes #8863
2013-11-22std::rand: move TaskRng off @mut.Huon Wilson-30/+43
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-39/+122
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-11Move std::rt::io to std::ioAlex Crichton-4/+4
2013-11-11Remove #[fixed_stack_segment] and #[rust_stack]Alex Crichton-3/+6
These two attributes are no longer useful now that Rust has decided to leave segmented stacks behind. It is assumed that the rust task's stack is always large enough to make an FFI call (due to the stack being very large). There's always the case of stack overflow, however, to consider. This does not change the behavior of stack overflow in Rust. This is still normally triggered by the __morestack function and aborts the whole process. C stack overflow will continue to corrupt the stack, however (as it did before this commit as well). The future improvement of a guard page at the end of every rust stack is still unimplemented and is intended to be the mechanism through which we attempt to detect C stack overflow. Closes #8822 Closes #10155
2013-11-03Fill out the remaining functionality in io::fileAlex Crichton-4/+4
This adds bindings to the remaining functions provided by libuv, all of which are useful operations on files which need to get exposed somehow. Some highlights: * Dropped `FileReader` and `FileWriter` and `FileStream` for one `File` type * Moved all file-related methods to be static methods under `File` * All directory related methods are still top-level functions * Created `io::FilePermission` types (backed by u32) that are what you'd expect * Created `io::FileType` and refactored `FileStat` to use FileType and FilePermission * Removed the expanding matrix of `FileMode` operations. The mode of reading a file will not have the O_CREAT flag, but a write mode will always have the O_CREAT flag. Closes #10130 Closes #10131 Closes #10121
2013-11-03Remove all blocking std::os blocking functionsAlex Crichton-3/+5
This commit moves all thread-blocking I/O functions from the std::os module. Their replacements can be found in either std::rt::io::file or in a hidden "old_os" module inside of native::file. I didn't want to outright delete these functions because they have a lot of special casing learned over time for each OS/platform, and I imagine that these will someday get integrated into a blocking implementation of IoFactory. For now, they're moved to a private module to prevent bitrot and still have tests to ensure that they work. I've also expanded the extensions to a few more methods defined on Path, most of which were previously defined in std::os but now have non-thread-blocking implementations as part of using the current IoFactory. The api of io::file is in flux, but I plan on changing it in the next commit as well. Closes #10057
2013-11-01auto merge of #10223 : huonw/rust/gamma, r=cmrbors-18/+234
Implements the [Gamma distribution](https://en.wikipedia.org/wiki/Gamma_distribution), using the algorithm described by Marsaglia & Tsang 2000[1]. I added tests checking that the mean and variance of this implementation is as expected for a range of values of the parameters in https://github.com/huonw/random-tests/commit/5d87c00a0fb69c8fa173593714cef76ddfddb651 (they pass locally, but obviously won't even build on Travis until this is merged). Also, moves `std::rand::distributions` to a subfolder, and performs a minor clean-up of the benchmarking (makes the number of iterations shared by the whole `std::rand` subtree). [1]: George Marsaglia and Wai Wan Tsang. 2000. "A Simple Method for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3 (September 2000), 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414).
2013-11-01auto merge of #10213 : telotortium/rust/rand-fill_bytes-stack-overflow, r=huonwbors-1/+21
Fix the implementation of `std::rand::Rng::fill_bytes()` for `std::rand::reseeding::ReseedingRng` to call the `fill_bytes()` method of the underlying RNG rather than itself, which causes infinite recursion. Fixes #10202.
2013-11-01std::rand: share the benchmark counter among the whole module tree.Huon Wilson-24/+21
2013-11-01std::rand: Implement the Gamma distribution.Huon Wilson-0/+219
2013-11-01std::rand: Move distributions to a subfolder.Huon Wilson-0/+0
2013-10-31Fix infinite recursion in `fill_bytes()`Robert Irelan-1/+21
Fix the implementation of `std::rand::Rng::fill_bytes()` for `std::rand::reseeding::ReseedingRng` to call the `fill_bytes()` method of the underlying RNG rather than itself, which causes infinite recursion. Fixes #10202.
2013-10-31std::rand: correct an off-by-one in the Ziggurat code.Huon Wilson-136/+3
The code was using (in the notation of Doornik 2005) `f(x_{i+1}) - f(x_{i+2})` rather than `f(x_i) - f(x_{i+1})`. This corrects that, and removes the F_DIFF tables which caused this problem in the first place. They `F_DIFF` tables are a micro-optimisation (in theory, they could easily be a micro-pessimisation): that `if` gets hit about 1% of the time for Exp/Normal, and the rest of the condition involves RNG calls and a floating point `exp`, so it is unlikely that saving a single FP subtraction will be very useful (especially as more tables means more memory reads and higher cache pressure, as well as taking up space in the binary (although only ~2k in this case)). Closes #10084. Notably, unlike that issue suggests, this wasn't a problem with the Exp tables. It affected Normal too, but since it is symmetric, there was no bias in the mean (as the bias was equal on the positive and negative sides and so cancelled out) but it was visible as a variance slightly lower than it should be.
2013-10-28Remove the extension traits for Readers/WritersAlex Crichton-5/+4
These methods are all excellent candidates for default methods, so there's no need to require extra imports of various traits.
2013-10-23auto merge of #9810 : huonw/rust/rand3, r=alexcrichtonbors-232/+823
- 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: seed ISAAC with no transmutes.Huon Wilson-7/+16
Slice transmutes are now (and, really, always were) dangerous, so we avoid them and do the (only?) non-(undefined behaviour in C) pointer cast: casting to *u8.
2013-10-23std::rand: use "nothing up your sleeve numbers" for ISAAC tests.Huon Wilson-18/+18
There's no value in using the "random" numbers, when nothing up your sleeve numbers are perfectly serviceable. http://en.wikipedia.org/wiki/Nothing_up_my_sleeve_number
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.