Skip to content

Commit d39ab55

Browse files
authored
Adding explanation to seeded rng used in examples (#12593)
# Objective - Fixes #12544 ## Solution - Added/updated a universally worded comment to all seeded rng instances in our examples.
1 parent b7ab146 commit d39ab55

File tree

11 files changed

+34
-1
lines changed

11 files changed

+34
-1
lines changed

examples/3d/spotlight.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ fn setup(
4949
));
5050

5151
// cubes
52+
53+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
54+
// This isn't strictly required in practical use unless you need your app to be deterministic.
5255
let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
5356
let cube_mesh = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
5457
let blue = materials.add(Color::srgb_u8(124, 144, 255));

examples/animation/custom_skinned_mesh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ fn setup(
123123

124124
let mesh = meshes.add(mesh);
125125

126+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
127+
// This isn't strictly required in practical use unless you need your app to be deterministic.
126128
let mut rng = ChaCha8Rng::seed_from_u64(42);
127129

128130
for i in -5..5 {

examples/async_tasks/external_source_external_thread.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ fn setup(mut commands: Commands) {
2727

2828
let (tx, rx) = bounded::<u32>(10);
2929
std::thread::spawn(move || {
30+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
31+
// This isn't strictly required in practical use unless you need your app to be deterministic.
3032
let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
3133
loop {
3234
// Everything here happens in another thread

examples/ecs/iter_combinations.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ fn generate_bodies(
4545
let color_range = 0.5..1.0;
4646
let vel_range = -0.5..0.5;
4747

48+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
49+
// This isn't strictly required in practical use unless you need your app to be deterministic.
4850
let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
4951
for _ in 0..NUM_BODIES {
5052
let radius: f32 = rng.gen_range(0.1..0.7);

examples/ecs/parallel_query.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ struct Velocity(Vec2);
1111
fn spawn_system(mut commands: Commands, asset_server: Res<AssetServer>) {
1212
commands.spawn(Camera2dBundle::default());
1313
let texture = asset_server.load("branding/icon.png");
14+
15+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
16+
// This isn't strictly required in practical use unless you need your app to be deterministic.
1417
let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
1518
for _ in 0..128 {
1619
commands.spawn((

examples/games/alien_cake_addict.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {
110110

111111
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
112112
let mut rng = if std::env::var("GITHUB_ACTIONS") == Ok("true".to_string()) {
113-
// Make the game play out the same way every time, this is useful for testing purposes.
113+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
114+
// This isn't strictly required in practical use unless you need your app to be deterministic.
114115
ChaCha8Rng::seed_from_u64(19878367467713)
115116
} else {
116117
ChaCha8Rng::from_entropy()

examples/gizmos/axes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ fn setup(
4242
mut meshes: ResMut<Assets<Mesh>>,
4343
mut materials: ResMut<Assets<StandardMaterial>>,
4444
) {
45+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
46+
// This isn't strictly required in practical use unless you need your app to be deterministic.
4547
let mut rng = ChaCha8Rng::seed_from_u64(19878367467713);
4648

4749
// Lights...

examples/stress_tests/bevymark.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ fn setup(
222222
quad: meshes
223223
.add(Rectangle::from_size(Vec2::splat(BIRD_TEXTURE_SIZE as f32)))
224224
.into(),
225+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
226+
// This isn't strictly required in practical use unless you need your app to be deterministic.
225227
color_rng: ChaCha8Rng::seed_from_u64(42),
226228
material_rng: ChaCha8Rng::seed_from_u64(42),
227229
velocity_rng: ChaCha8Rng::seed_from_u64(42),
@@ -305,6 +307,8 @@ fn mouse_handler(
305307
mut wave: Local<usize>,
306308
) {
307309
if rng.is_none() {
310+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
311+
// This isn't strictly required in practical use unless you need your app to be deterministic.
308312
*rng = Some(ChaCha8Rng::seed_from_u64(42));
309313
}
310314
let rng = rng.as_mut().unwrap();
@@ -538,6 +542,8 @@ fn counter_system(
538542
}
539543

540544
fn init_textures(textures: &mut Vec<Handle<Image>>, args: &Args, images: &mut Assets<Image>) {
545+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
546+
// This isn't strictly required in practical use unless you need your app to be deterministic.
541547
let mut color_rng = ChaCha8Rng::seed_from_u64(42);
542548
while textures.len() < args.material_texture_count {
543549
let pixel = [color_rng.gen(), color_rng.gen(), color_rng.gen(), 255];
@@ -573,6 +579,8 @@ fn init_materials(
573579
texture: textures.first().cloned(),
574580
}));
575581

582+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
583+
// This isn't strictly required in practical use unless you need your app to be deterministic.
576584
let mut color_rng = ChaCha8Rng::seed_from_u64(42);
577585
let mut texture_rng = ChaCha8Rng::seed_from_u64(42);
578586
materials.extend(

examples/stress_tests/many_cubes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ fn setup(
124124
let material_textures = init_textures(args, images);
125125
let materials = init_materials(args, &material_textures, material_assets);
126126

127+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
128+
// This isn't strictly required in practical use unless you need your app to be deterministic.
127129
let mut material_rng = ChaCha8Rng::seed_from_u64(42);
128130
match args.layout {
129131
Layout::Sphere => {
@@ -203,6 +205,8 @@ fn setup(
203205
}
204206

205207
fn init_textures(args: &Args, images: &mut Assets<Image>) -> Vec<Handle<Image>> {
208+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
209+
// This isn't strictly required in practical use unless you need your app to be deterministic.
206210
let mut color_rng = ChaCha8Rng::seed_from_u64(42);
207211
let color_bytes: Vec<u8> = (0..(args.material_texture_count * 4))
208212
.map(|i| if (i % 4) == 3 { 255 } else { color_rng.gen() })
@@ -247,6 +251,8 @@ fn init_materials(
247251
..default()
248252
}));
249253

254+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
255+
// This isn't strictly required in practical use unless you need your app to be deterministic.
250256
let mut color_rng = ChaCha8Rng::seed_from_u64(42);
251257
let mut texture_rng = ChaCha8Rng::seed_from_u64(42);
252258
materials.extend(

examples/transforms/align.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ fn setup(
5454
mut meshes: ResMut<Assets<Mesh>>,
5555
mut materials: ResMut<Assets<StandardMaterial>>,
5656
) {
57+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
58+
// This isn't strictly required in practical use unless you need your app to be deterministic.
5759
let mut seeded_rng = ChaCha8Rng::seed_from_u64(19878367467712);
5860

5961
// A camera looking at the origin

examples/ui/font_atlas_debug.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut state: ResM
105105
},
106106
));
107107
});
108+
// We're seeding the PRNG here to make this example deterministic for testing purposes.
109+
// This isn't strictly required in practical use unless you need your app to be deterministic.
108110
commands.insert_resource(SeededRng(ChaCha8Rng::seed_from_u64(19878367467713)));
109111
}

0 commit comments

Comments
 (0)