diff --git a/simul.h b/simul.h index b62132a..5a2201b 100644 --- a/simul.h +++ b/simul.h @@ -18,6 +18,10 @@ class simul { int l, r, mid; double prb = random() * arr[len - 1]; + // if the final value is zero, pick a random index from the array. + if (arr[len - 1] == 0.0) { + return random() * (len - 1); + } l = 0; r = len - 1; while (l <= r) { @@ -40,4 +44,3 @@ class simul { }; #endif /* SIMUL_H_ */ -