Skip to content

Add RngUtils::sample() method for reservoir sampling from iterators #8491

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

Closed

Conversation

robertknight
Copy link
Contributor

Fixes #7722

I had a couple of queries:

  • Should this return an array or an iterator?
  • Should this be a method on iterators or on the rng? I implemented it in RngUtils as it seemed to belong with shuffle().

@graydon
Copy link
Contributor

graydon commented Aug 13, 2013

I think returning the sampling array is fine since the algorithm is more or less defined in terms of such an array. It has to exist, might as well return it. As for whether to put this on Rng or Iterator, I think it's mostly a matter of where people will look for such a thing. And I suspect they'll look in the rand module. So I'm happy enough with this as-is.

Thanks so much!

bors added a commit that referenced this pull request Aug 15, 2013
…aydon

Fixes #7722

I had a couple of queries:
- Should this return an array or an iterator?
- Should this be a method on iterators or on the rng? I implemented it in RngUtils as it seemed to belong with shuffle().
@bors bors closed this Aug 15, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 14, 2022
tests: use std::thread::available_parallelism() instead of num_cpus to get thread count

removes the dependency added in rust-lang/rust-clippy#8451
---

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: tests: use std::thread::available_parallelism() instead of num_cpus to get thread count
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.

provide reservoir sampling for iterators
4 participants