Skip to content

Add random_query example #3704

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
wants to merge 3 commits into from
Closed

Add random_query example #3704

wants to merge 3 commits into from

Conversation

mfdorst
Copy link
Contributor

@mfdorst mfdorst commented Jan 16, 2022

Objective

Showcase how to select random elements from a query, as requested in #3652.

Solution

Add an example that shows how one can use rand::seq::IteratorRandom::choose and rand::seq::IteratorRandom::choose_multiple to choose one or multiple random items from a query.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Jan 16, 2022
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples and removed S-Needs-Triage This issue needs to be labelled labels Jan 16, 2022
}

fn generate_pets(mut commands: Commands) {
let pets = ['🐀', '🐄', '🐅', '🐇', '🐊', '🐓', '🐖'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small description nit, but this example is excellent. Very clear, and it's a very handy trick. Thanks!

Co-authored-by: Alice Cecile <[email protected]>
@IceSentry
Copy link
Contributor

There doesn't seem to be anything bevy specific about this example, this is only showing how to use the IteratorRandom trait from rand. Do we really need an example for that?

@alice-i-cecile
Copy link
Member

Point taken. We can integrate this into a game example as the need arises. Closing down this and the originating issue as this was much easier than I expected at first glance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Examples An addition or correction to our examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants