about summary refs log tree commit diff
path: root/src/libstd/rand
AgeCommit message (Collapse)AuthorLines
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.
2013-10-23std::rand: move Weighted to distributions.Huon Wilson-132/+207
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: optimise & document ziggurat.Huon Wilson-8/+72
Before: test rand::distributions::bench::rand_exp ... bench: 1399 ns/iter (+/- 124) = 571 MB/s test rand::distributions::bench::rand_normal ... bench: 1611 ns/iter (+/- 123) = 496 MB/s After: test rand::distributions::bench::rand_exp ... bench: 712 ns/iter (+/- 43) = 1123 MB/s test rand::distributions::bench::rand_normal ... bench: 1007 ns/iter (+/- 81) = 794 MB/s
2013-10-23std::rand: documentation & references.Huon Wilson-44/+100
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/+272
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-23std::rand: full exponential & normal distributionsHuon Wilson-20/+116
Complete the implementation of Exp and Normal started by Exp1 and StandardNormal by creating types implementing Sample & IndependentSample with the appropriate parameters.
2013-10-23std::rand: Add RandSample for Sample-ing Rand types directly.Huon Wilson-0/+35
2013-10-23std::rand: add the Sample and IndependentSample traits.Huon Wilson-0/+18
These are a "parameterised" Rand.
2013-10-22Drop the '2' suffix from logging macrosAlex Crichton-7/+7
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/+11
2013-10-09std::rand::os: use the externfn! macro for the Windows RNG.Huon Wilson-22/+16
2013-10-09std::rand::reseeding: seed the reseeder in the SeedableRng impl.Huon Wilson-12/+13
This stops us relying on Default here.
2013-10-09std::rand::reader: describe cfg!(endianness).Huon Wilson-0/+4
2013-10-09std::rand: Correct the implementation of Rand for f32 & f64.Huon Wilson-8/+29
2013-10-09Documentation & address minor point.Huon Wilson-4/+8
2013-10-09std::rand: remove `seed`.Huon Wilson-52/+42
This much better handled by directly calling out to `OSRng` where appropriate.