Skip to content

Commit bb8ec67

Browse files
committed
Adding explanation to seeded rng used in examples
1 parent f38895a commit bb8ec67

File tree

11 files changed

+19
-2
lines changed

11 files changed

+19
-2
lines changed

examples/3d/spotlight.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fn setup(
4848
));
4949

5050
// cubes
51+
52+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
5153
let mut rng = StdRng::seed_from_u64(19878367467713);
5254
let cube_mesh = meshes.add(Cuboid::new(0.5, 0.5, 0.5));
5355
let blue = materials.add(Color::srgb_u8(124, 144, 255));

examples/animation/custom_skinned_mesh.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ fn setup(
122122

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

125+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
125126
let mut rng = StdRng::seed_from_u64(42);
126127

127128
for i in -5..5 {

examples/async_tasks/external_source_external_thread.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ fn setup(mut commands: Commands) {
2525
commands.spawn(Camera2dBundle::default());
2626

2727
let (tx, rx) = bounded::<u32>(10);
28-
std::thread::spawn(move || {
28+
std::thread::spawn(move || {
29+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
2930
let mut rng = StdRng::seed_from_u64(19878367467713);
3031
loop {
3132
// Everything here happens in another thread

examples/ecs/iter_combinations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn generate_bodies(
4444
let color_range = 0.5..1.0;
4545
let vel_range = -0.5..0.5;
4646

47+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
4748
let mut rng = StdRng::seed_from_u64(19878367467713);
4849
for _ in 0..NUM_BODIES {
4950
let radius: f32 = rng.gen_range(0.1..0.7);

examples/ecs/parallel_query.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct Velocity(Vec2);
1010
fn spawn_system(mut commands: Commands, asset_server: Res<AssetServer>) {
1111
commands.spawn(Camera2dBundle::default());
1212
let texture = asset_server.load("branding/icon.png");
13+
14+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
1315
let mut rng = StdRng::seed_from_u64(19878367467713);
1416
for _ in 0..128 {
1517
commands.spawn((

examples/games/alien_cake_addict.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn setup_cameras(mut commands: Commands, mut game: ResMut<Game>) {
109109

110110
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMut<Game>) {
111111
let mut rng = if std::env::var("GITHUB_ACTIONS") == Ok("true".to_string()) {
112-
// Make the game play out the same way every time, this is useful for testing purposes.
112+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
113113
StdRng::seed_from_u64(19878367467713)
114114
} else {
115115
StdRng::from_entropy()

examples/gizmos/axes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ fn setup(
4141
mut meshes: ResMut<Assets<Mesh>>,
4242
mut materials: ResMut<Assets<StandardMaterial>>,
4343
) {
44+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
4445
let mut rng = StdRng::seed_from_u64(19878367467713);
4546

4647
// Lights...

examples/stress_tests/bevymark.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ fn setup(
221221
quad: meshes
222222
.add(Rectangle::from_size(Vec2::splat(BIRD_TEXTURE_SIZE as f32)))
223223
.into(),
224+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
224225
color_rng: StdRng::seed_from_u64(42),
225226
material_rng: StdRng::seed_from_u64(42),
226227
velocity_rng: StdRng::seed_from_u64(42),
@@ -304,6 +305,7 @@ fn mouse_handler(
304305
mut wave: Local<usize>,
305306
) {
306307
if rng.is_none() {
308+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
307309
*rng = Some(StdRng::seed_from_u64(42));
308310
}
309311
let rng = rng.as_mut().unwrap();
@@ -537,6 +539,7 @@ fn counter_system(
537539
}
538540

539541
fn init_textures(textures: &mut Vec<Handle<Image>>, args: &Args, images: &mut Assets<Image>) {
542+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
540543
let mut color_rng = StdRng::seed_from_u64(42);
541544
while textures.len() < args.material_texture_count {
542545
let pixel = [color_rng.gen(), color_rng.gen(), color_rng.gen(), 255];
@@ -572,6 +575,7 @@ fn init_materials(
572575
texture: textures.first().cloned(),
573576
}));
574577

578+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
575579
let mut color_rng = StdRng::seed_from_u64(42);
576580
let mut texture_rng = StdRng::seed_from_u64(42);
577581
materials.extend(

examples/stress_tests/many_cubes.rs

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

126+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
126127
let mut material_rng = StdRng::seed_from_u64(42);
127128
match args.layout {
128129
Layout::Sphere => {
@@ -202,6 +203,7 @@ fn setup(
202203
}
203204

204205
fn init_textures(args: &Args, images: &mut Assets<Image>) -> Vec<Handle<Image>> {
206+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
205207
let mut color_rng = StdRng::seed_from_u64(42);
206208
let color_bytes: Vec<u8> = (0..(args.material_texture_count * 4))
207209
.map(|i| if (i % 4) == 3 { 255 } else { color_rng.gen() })
@@ -246,6 +248,7 @@ fn init_materials(
246248
..default()
247249
}));
248250

251+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
249252
let mut color_rng = StdRng::seed_from_u64(42);
250253
let mut texture_rng = StdRng::seed_from_u64(42);
251254
materials.extend(

examples/transforms/align.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn setup(
5353
mut meshes: ResMut<Assets<Mesh>>,
5454
mut materials: ResMut<Assets<StandardMaterial>>,
5555
) {
56+
// Make it play out the same way every time with deterministic results. We do this for testing purposes.
5657
let mut seeded_rng = StdRng::seed_from_u64(19878367467712);
5758

5859
// A camera looking at the origin

0 commit comments

Comments
 (0)