Skip to content

Commit a6d2339

Browse files
authored
Fix ecs example thread_rng duplicate creation (#14795)
# Objective While looking through the changes #14782 will create I noticed this. ## Solution Reuse the existing thread_rng. As this is a code change I would like to not include it in a pure lint enable PR. ## Testing I did not test this change (other than the automated CI with this PR). I think it should be a fairly simple change that can be reviewed only by the code.
1 parent 618cf7f commit a6d2339

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

examples/ecs/observer_propagation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ struct Armor(u16);
6969

7070
/// A normal bevy system that attacks a piece of the goblin's armor on a timer.
7171
fn attack_armor(entities: Query<Entity, With<Armor>>, mut commands: Commands) {
72-
let mut rng = rand::thread_rng();
72+
let mut rng = thread_rng();
7373
if let Some(target) = entities.iter().choose(&mut rng) {
74-
let damage = thread_rng().gen_range(1..20);
74+
let damage = rng.gen_range(1..20);
7575
commands.trigger_targets(Attack { damage }, target);
7676
info!("⚔️ Attack for {} damage", damage);
7777
}

0 commit comments

Comments
 (0)