From ff3f3c12bf1bd294928448d7b997b2e16a71ead7 Mon Sep 17 00:00:00 2001 From: Timo Schneider Date: Thu, 2 May 2024 08:29:40 +0200 Subject: [PATCH] corrected sample count --- src/function.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/function.rs b/src/function.rs index 35f24f5..e9e3bac 100644 --- a/src/function.rs +++ b/src/function.rs @@ -42,7 +42,7 @@ impl Function { threads.push(std::thread::spawn(move || { let mut hits: u64 = 0; - for _ in 0..samples { + for _ in 0..samples/thread_cnt { let point: Point = bounds.get_random_point(); if function.includes(&point) { hits += 1; @@ -52,10 +52,17 @@ impl Function { })) } + for _ in 0..samples % thread_cnt { + let point: Point = bounds.get_random_point(); + if function.includes(&point) { + hits += 1; + } + } + for thread in threads { hits += thread.join().unwrap(); } - return (hits as f64 / (thread_cnt * samples) as f64) * bounds.get_area(); + return (hits as f64 / samples as f64) * bounds.get_area(); } } \ No newline at end of file