Skip to content

Commit 82a460d

Browse files
authored
Update rand to v0.10.0 and getrandom to v0.4.1 (#336)
1 parent bf2e769 commit 82a460d

5 files changed

Lines changed: 24 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ colorous = "1.0.12"
175175
web-time = "1.0.0"
176176
winit = { version = "0.30.0", default-features = false, features = ["rwh_06"] }
177177
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
178-
glam = { version = "0.31.0", features = ["rand"] }
179-
rand = "0.9.2"
178+
glam = "0.31.0"
179+
rand = "0.10.0"
180180
# Disable unnecessary formats.
181181
image = { version = "0.25.0", default-features = false, features = ["jpeg"] }
182182

@@ -199,7 +199,7 @@ wasm-bindgen-test = "0.3"
199199
console_error_panic_hook = "0.1"
200200
tracing-web = "0.1"
201201
# Allow `rand` crate to compile.
202-
getrandom = { version = "0.3.4", features = ["wasm_js"] }
202+
getrandom = { version = "0.4.1", features = ["wasm_js"] }
203203

204204
# DRM example.
205205
[target.'cfg(not(any(target_os = "android", target_vendor = "apple", target_os = "redox", target_family = "wasm", target_os = "windows")))'.dev-dependencies]

examples/raytracing/game.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::time::{Duration, Instant};
22

3-
use rand::rngs::SmallRng;
4-
use rand::{Rng, SeedableRng};
3+
use rand::rngs::{SmallRng, SysRng};
4+
use rand::{RngExt, SeedableRng};
55
use softbuffer::{Buffer, Pixel};
66

77
use crate::camera::Camera;
@@ -27,7 +27,7 @@ const DURATION_BETWEEN_TICKS: Duration = Duration::from_millis(10);
2727

2828
impl Game {
2929
pub fn new() -> Self {
30-
let mut rng = SmallRng::from_os_rng();
30+
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
3131
let position = Point3::new(13.0, 2.0, 3.0);
3232
let looking_at = Point3::new(0.0, 0.0, 0.0);
3333
let camera_direction = (looking_at - position).normalize();
@@ -91,16 +91,14 @@ impl Game {
9191
{
9292
use rayon::prelude::*;
9393

94-
pixels
95-
.par_iter_mut()
96-
.enumerate()
97-
.for_each_init(SmallRng::from_os_rng, move |rng, (i, pixel)| {
98-
each_pixel(rng, i, pixel)
99-
});
94+
pixels.par_iter_mut().enumerate().for_each_init(
95+
|| SmallRng::try_from_rng(&mut SysRng).unwrap(),
96+
move |rng, (i, pixel)| each_pixel(rng, i, pixel),
97+
);
10098
};
10199
#[cfg(target_family = "wasm")]
102100
{
103-
let mut rng = SmallRng::from_os_rng();
101+
let mut rng = SmallRng::try_from_rng(&mut SysRng).unwrap();
104102
pixels
105103
.iter_mut()
106104
.enumerate()

examples/raytracing/material.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::Rng;
1+
use rand::{Rng, RngExt};
22

33
use crate::objects::Hit;
44
use crate::ray::Ray;

examples/raytracing/vec3.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
use rand::Rng;
1+
use rand::{Rng, RngExt};
22

33
pub use glam::Vec3;
44
pub type Point3 = Vec3;
55
pub type Color = Vec3;
66

7+
pub fn random_color(rng: &mut impl Rng) -> Color {
8+
Vec3::new(
9+
rng.random_range(0.0..=1.0),
10+
rng.random_range(0.0..=1.0),
11+
rng.random_range(0.0..=1.0),
12+
)
13+
}
14+
715
pub fn random_in_unit_sphere(rng: &mut impl Rng) -> Vec3 {
816
loop {
917
let p = Vec3::new(

examples/raytracing/world.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::ops::Range;
22

3-
use rand::Rng;
3+
use rand::{Rng, RngExt};
44

55
use crate::material::{Dielectric, Lambertian, Material, Metal};
66
use crate::objects::{Hit, Sphere};
77
use crate::ray::Ray;
8-
use crate::vec3::{Color, Point3, Vec3};
8+
use crate::vec3::{random_color, Color, Point3, Vec3};
99

1010
#[derive(Default, Debug)]
1111
pub struct World {
@@ -35,7 +35,7 @@ impl World {
3535
if (center - Point3::new(4.0, 0.2, 0.0)).length() > 0.9 {
3636
if choose_mat < 0.8 {
3737
// Diffuse
38-
let albedo = rng.random::<Color>() * rng.random::<Color>();
38+
let albedo = random_color(rng) * random_color(rng);
3939
let sphere_material = Material::Lambertian(Lambertian::new(albedo));
4040
spheres.push(Sphere::new(center, 0.2, sphere_material));
4141
} else if choose_mat < 0.95 {

0 commit comments

Comments
 (0)