corrected sample count
This commit is contained in:
@@ -42,7 +42,7 @@ impl Function {
|
|||||||
|
|
||||||
threads.push(std::thread::spawn(move || {
|
threads.push(std::thread::spawn(move || {
|
||||||
let mut hits: u64 = 0;
|
let mut hits: u64 = 0;
|
||||||
for _ in 0..samples {
|
for _ in 0..samples/thread_cnt {
|
||||||
let point: Point = bounds.get_random_point();
|
let point: Point = bounds.get_random_point();
|
||||||
if function.includes(&point) {
|
if function.includes(&point) {
|
||||||
hits += 1;
|
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 {
|
for thread in threads {
|
||||||
hits += thread.join().unwrap();
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user