about summary refs log tree commit diff
path: root/src/libstd/rand
AgeCommit message (Collapse)AuthorLines
2013-10-09std::rand: adjust the f32 & f64 Rand instances.Huon Wilson-7/+8
The f32 generator now just uses a single u32, and the f64 uses a single u64. This will make both significantly faster, especially on 64-bit platforms.
2013-10-09std::rand: documentation additions & fixes.Huon Wilson-9/+52
2013-10-09std::rand: move the Rand impls into a separate file for neatness.Huon Wilson-167/+201
2013-10-09std::rand: add & split some tests.Huon Wilson-7/+82
2013-10-09std::rand: make the windows OSRng more correct, remove some C++.Huon Wilson-34/+49
This lets the C++ code in the rt handle the (slightly) tricky parts of random number generation: e.g. error detection/handling, and using the values of the `#define`d options to the various functions.
2013-10-09std::rand: improve the task_rng code.Huon Wilson-20/+134
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-102/+221
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/+129
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/+380
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-49/+280
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/+207
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-20/+20
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-32/+32
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.
2013-09-23std: merge rand::{Rng,RngUtil} with default methods.Huon Wilson-349/+272
Also, documentation & general clean-up: - remove `gen_char_from`: better served by `sample` or `choose`. - `gen_bytes` generalised to `gen_vec`. - `gen_int_range`/`gen_uint_range` merged into `gen_integer_range` and made to be properly uniformly distributed. Fixes #8644. Minor adjustments to other functions.
2013-09-22std: move rand.rs to rand/mod.rs.Huon Wilson-0/+1224
2013-08-21std/extra: changing XXX to FIXME; cleanupTim Chevalier-1/+1
* Get rid of by-value-self workarounds; it works now * Remove type annotations, they're not needed anymore
2013-08-16doc: convert remaining uses of core:: to std::.Huon Wilson-2/+2
2013-07-24Change 'print(fmt!(...))' to printf!/printfln! in src/lib*Birunthan Mohanathas-2/+2
2013-07-08 Replaces the free-standing functions in f32, &c.Jens Nockert-12/+13
The free-standing functions in f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, float, int, and uint are replaced with generic functions in num instead. If you were previously using any of those functions, just replace them with the corresponding function with the same name in num. Note: If you were using a function that corresponds to an operator, use the operator instead.
2013-06-28librustc: Disallow "mut" from distributing over bindings.Patrick Walton-1/+2
This is the backwards-incompatible part of per-binding-site "mut".
2013-06-18replace #[inline(always)] with #[inline]. r=burningtree.Graydon Hoare-5/+5
2013-06-04librustc: Disallow multiple patterns from appearing in a "let" declaration.Patrick Walton-1/+1
You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
2013-05-30Remove unnecessary 'use' formsDaniel Farina-1/+0
Fix a laundry list of warnings involving unused imports that glutted up compilation output. There are more, but there seems to be some false positives (where 'remedy' appears to break the build), but this particular set of fixes seems safe.
2013-05-29librustc: Stop reexporting the standard modules from prelude.Patrick Walton-0/+1
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+560
This only changes the directory names; it does not change the "real" metadata names.