|
@@ -366,6 +366,7 @@ impl RandomizePen {
|
|
|
);
|
|
|
|
|
|
let mut generated: Vec<RandomizedSetting> = vec![];
|
|
|
+ const MAX_ATTEMPTS: usize = 1000;
|
|
|
|
|
|
for (index, pen) in pens
|
|
|
.iter_mut()
|
|
@@ -373,7 +374,7 @@ impl RandomizePen {
|
|
|
.take(self.count)
|
|
|
.enumerate()
|
|
|
{
|
|
|
- loop {
|
|
|
+ for attempt in 0..=MAX_ATTEMPTS {
|
|
|
let mut setting: RandomizedSetting = RandomizedSetting::default();
|
|
|
|
|
|
if let Some((min, max, step)) = self.speed {
|
|
@@ -430,6 +431,13 @@ impl RandomizePen {
|
|
|
} else {
|
|
|
debug!("Duplicate random setting");
|
|
|
}
|
|
|
+
|
|
|
+ if attempt == MAX_ATTEMPTS {
|
|
|
+ panic!(
|
|
|
+ "Exceeded maximum number of {} randommization attempts",
|
|
|
+ MAX_ATTEMPTS
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
pen.valid_settings();
|