Skip to content

libcore: rand refactor & remove @'s from {rand,run}.rs #6036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2013

Conversation

huonw
Copy link
Member

@huonw huonw commented Apr 23, 2013

From a cursory git grep this removes the last part of core that requires on @ (other than io and the task local data section).

It renames RandRes to StdRng IsaacRng and XorShiftState to XorShiftRng as well as moving their constructors to static methods. To go with this, it adds rng() which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used.

It also removes all the gen_int, gen_uint, gen_char (etc) methods on RngUtil (by moving the defintions to the actual Rand instances). The replacement is using RngUtil::gen, either type-inferred or with an annotation (rng.gen::<uint>()).

I tried to have the Rng and RngUtil traits exported by core::prelude (since core::rand (except for random()) is useless without them), but this caused an explosion of (seemingly unrelated) error: unresolved import's.

@z0w0
Copy link
Contributor

z0w0 commented Apr 24, 2013

I feel like rand::IsaacRng would be a better name than StdRng.

@huonw
Copy link
Member Author

huonw commented Apr 24, 2013

That seems reasonable. (edit: done!)

huonw added 4 commits April 24, 2013 22:34
Also, rename RandRes -> IsaacRng, and make the constructors static
methods.
Removes the dynamic @ indirection, and also converts the functions acting
on `ProgRepr`s to methods.
…ic `gen`.

This moves all the basic random value generation into the Rand instances for
each type and then removes the `gen_int`, `gen_char` (etc) methods on RngUtil,
leaving only the generic `gen` and the more specialised methods.

Also, removes some imports that are redundant due to a `use core::prelude::*`
statement.
@nikomatsakis
Copy link
Contributor

r+ This looks good; we may also want to implement the trait Rng for the object type @Rng:

impl Rng for @Rng { pub fn next(&self) -> u32 { self.next() } }

so that people can use the object type should they choose to (sometimes it's more convenient).

@nikomatsakis
Copy link
Contributor

Oh, I see you already did that, I missed it.

bors added a commit that referenced this pull request Apr 24, 2013
From a cursory `git grep` this removes the last part of `core` that requires on `@` (other than `io` and the task local data section).

It renames `RandRes` to ~~StdRng~~ `IsaacRng` and `XorShiftState` to `XorShiftRng` as well as moving their constructors to static methods. To go with this, it adds `rng()` which is designed to be used when the programmer just wants a random number generator, without caring about which exact algorithm is being used.

It also removes all the `gen_int`, `gen_uint`, `gen_char` (etc) methods on `RngUtil` (by moving the defintions to the actual `Rand` instances). The replacement is using `RngUtil::gen`, either type-inferred or with an annotation (`rng.gen::<uint>()`).

I tried to have the `Rng` and `RngUtil` traits exported by `core::prelude` (since `core::rand` (except for `random()`) is useless without them), but this caused [an explosion of (seemingly unrelated) `error: unresolved import`'s](https://gist.github.com/5451839).
@bors bors closed this Apr 24, 2013
@bors bors merged commit 9860fe1 into rust-lang:incoming Apr 24, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Sep 24, 2020
…ask_to_pedantic

Downgrade `verbose_bit_mask` to pedantic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants