-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Select a random element (or set of elements) from a query #3652
Comments
Of note: this will be trickiest with |
When implementing this for filters that involve |
@alice-i-cecile Is it possiple to implement |
Yep, looks like you're correct @mfdorst. |
Looks like |
On |
Oh, actually, from the
So I guess all the user needs to do is use rand::seq::IteratorRandom; and they will have this functionality already. |
Excellent! @mfdorst, could you make an example showcasing this? We can add |
For this method to be efficient, we should also consider adding a custom |
What problem does this solve or what need does it fill?
Selecting random elements is a common gameplay tasks. We can quickly and ergonomically generate possible lists of
What solution would you like?
Implement the SliceRandom trait forQuery
.Nope, this is not publically implementable. We have to use the alternative, implementing it for our associated iterator type.
Create an example.
What alternative(s) have you considered?
IteratorRandom
trait instead. Taking a look, our ability to mutate the elements of the query + desire to be able to shuffle the order probably makesSliceRandom
more fitting. More importantly,Query
isn't itself an iterator (nor should it be): being able to operate directly on a query rather thanquery.iter()
is more natural and convenient.Additional context
Related to #1470.
The text was updated successfully, but these errors were encountered: