-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Select a random element (or set of elements) from a query #3652
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Type
Fields
Give feedbackNo fields configured for issues without a type.
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?
IteratorRandomtrait instead. Taking a look, our ability to mutate the elements of the query + desire to be able to shuffle the order probably makesSliceRandommore fitting. More importantly,Queryisn'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.