From ef0c51d993c379ca461ce6f1d7bd2fceb2b1d6e4 Mon Sep 17 00:00:00 2001 From: Fabian Schmidt Date: Mon, 24 Feb 2025 09:56:23 +0100 Subject: [PATCH] Add js-sys crate to change initial Cell generation (50% random chance) --- Cargo.toml | 1 + src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1ba67db..e2021b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ wasm-bindgen = "0.2.100" # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # code size when deploying. console_error_panic_hook = { version = "0.1.7", optional = true } +js-sys = "0.3.77" [dev-dependencies] wasm-bindgen-test = "0.3.50" diff --git a/src/lib.rs b/src/lib.rs index d1d3b73..9abcce3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,8 +92,8 @@ impl Universe { let height = 64; let cells = (0..width * height) - .map(|i| { - if i % 2 == 0 || i % 7 == 0 { + .map(|_i| { + if js_sys::Math::random() < 0.5 { Cell::Alive } else { Cell::Dead