implement randomize for QueryIter#14407
Conversation
|
While I really like randomizing query orders for gameplay reasons, I don't think we should add this: randomization without a seed is a serious source of tech debt. See #2504 for some previous discussion. We could provide a better API by passing in an RNG, but that adds a dependency for pretty niche functionality. Ultimately I think the linked issue is better closed with an example, unless we want to add a full entropy / RNG solution. |
|
makes sense, this method is a simple convenience, and if there are serious implications to adding this to bevy itself, then it is better to have the implementation fall on the user. |
|
I would call it |
Objective
There is no out of the box way to randomize query iteration order. While order is currently not guaranteed, it is still deterministic.
Closes #14393
Solution
Implement a
randomizemethod forQueryIter. This uses a cached sort ofEntitywith its hash as the key.Since the underlying implementation is just a sort, it returns a type alias of
QuerySortedIter, namedQueryRandomIter.The same could be done for
QueryManyIterif #13443 merges.Testing
The example acts as a doc test.
Showcase
Fetch 7 random query items!
let random_items = query.iter().randomize().take(7);