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