From f44adaa764670b6439c8bccf784a0843de4fd631 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 6 Apr 2026 07:10:41 +0530 Subject: [PATCH] Fix simulate() returning 0 for unfailed components (#154) Components that never fail within max_steps were left with v[i,j]=0, incorrectly suggesting they failed at time 0. Initialize with max_steps instead, so unfailed components are distinguishable from those that failed early. --- .../simulating_component_failure.jl | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/data_science/simulating_component_failure.jl b/src/data_science/simulating_component_failure.jl index 29c93509..97a7c9b2 100644 --- a/src/data_science/simulating_component_failure.jl +++ b/src/data_science/simulating_component_failure.jl @@ -329,21 +329,21 @@ Note that does not require (or even allow) methods at first, as some other langu Base.rand(X::Binomial) = sum(rand(Bernoulli(X.p)) for i in 1:X.N) # ╔═╡ 178631ec-8cac-11eb-1117-5d872ba7f66e -function simulate(N, p) - v = fill(0, N, N) - t = 0 - - while any( v .== 0 ) && t < 100 +function simulate(N, p, max_steps=100) + v = fill(max_steps, N, N) + t = 0 + + while any( v .== max_steps ) && t < max_steps t += 1 - + for i= 1:N, j=1:N - if rand() < p && v[i,j]==0 + if rand() < p && v[i,j]==max_steps v[i,j] = t - end + end end - + end - + return v end