corrected sample count

This commit is contained in:
2024-05-02 08:29:40 +02:00
parent 74ea548338
commit ff3f3c12bf

View File

@@ -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();
}
}