Index: /trunk/autoquest-core-testgeneration/src/main/java/de/ugoe/cs/autoquest/testgeneration/RandomWalkGenerator.java
===================================================================
--- /trunk/autoquest-core-testgeneration/src/main/java/de/ugoe/cs/autoquest/testgeneration/RandomWalkGenerator.java	(revision 2025)
+++ /trunk/autoquest-core-testgeneration/src/main/java/de/ugoe/cs/autoquest/testgeneration/RandomWalkGenerator.java	(revision 2026)
@@ -74,4 +74,12 @@
     /**
      * <p>
+     * Maximal number of attempts for creating a valid sequence. If this value is reached, the
+     * sequence generation will be aborted.
+     * </p>
+     */
+    private final long maxIterValidSequence;
+
+    /**
+     * <p>
      * Actual number of random walks performed to generate the test suite.
      * </p>
@@ -103,4 +111,6 @@
      *            maximal number of random walks before aborting the test case generation (see
      *            {@link #maxIter})
+     * @param maxIterValidSequence
+     *            maximal number of attempts to create a valid sequence within the given restrictions
      */
     public RandomWalkGenerator(int numSequences,
@@ -108,5 +118,6 @@
                                int maxLength,
                                boolean validEnd,
-                               long maxIter)
+                               long maxIter,
+                               long maxIterValidSequence)
     {
         // check validity of the parameters
@@ -117,19 +128,22 @@
         if (maxLength < 1) {
             throw new IllegalArgumentException(
-                                                "maximal allowed length of test cases must be at least 1 but is " +
-                                                    maxLength);
+                                               "maximal allowed length of test cases must be at least 1 but is " +
+                                                   maxLength);
         }
         if (minLength > maxLength) {
             throw new IllegalArgumentException(
-                                                "minimal allowed length of test cases must be less than or equal to the maximal allowed length (min length: " +
-                                                    minLength + " ; max length: " + maxLength + ")");
+                                               "minimal allowed length of test cases must be less than or equal to the maximal allowed length (min length: " +
+                                                   minLength + " ; max length: " + maxLength + ")");
         }
         if (maxIter < numSequences) {
             throw new IllegalArgumentException(
-                                                "maximal number of iterations must greater than or equal to the number of sequences (number of sequences: " +
-                                                    numSequences +
-                                                    " ; max iterations: " +
-                                                    maxIter +
-                                                    ")");
+                                               "maximal number of iterations must greater than or equal to the number of sequences (number of sequences: " +
+                                                   numSequences +
+                                                   " ; max iterations: " +
+                                                   maxIter +
+                                                   ")");
+        }
+        if( maxIterValidSequence < 1) {
+            throw new IllegalArgumentException("maximal number of attempts to get a valid sequence must be positive, but is: " + maxIterValidSequence);
         }
         this.numSequences = numSequences;
@@ -138,4 +152,5 @@
         this.validEnd = validEnd;
         this.maxIter = maxIter;
+        this.maxIterValidSequence = maxIterValidSequence;
     }
 
@@ -157,5 +172,5 @@
         actualIter = 0;
         while (sequences.size() < numSequences && actualIter < maxIter) {
-            List<Event> generatedSequence = model.randomSequence(maxLength, validEnd);
+            List<Event> generatedSequence = model.randomSequence(maxLength, validEnd, maxIterValidSequence);
             if (generatedSequence.size() >= minLength && generatedSequence.size() <= maxLength) {
                 ((List<Event>) generatedSequence).add(0, Event.STARTEVENT);
Index: /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/IStochasticProcess.java
===================================================================
--- /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/IStochasticProcess.java	(revision 2025)
+++ /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/IStochasticProcess.java	(revision 2026)
@@ -61,10 +61,10 @@
      */
     double getProbability(List<Event> sequence);
-    
-    /**
-     * <p>
-     * Returns the sum of the negative logarithm of the probabilities. 
-     * </p>
-     *
+
+    /**
+     * <p>
+     * Returns the sum of the negative logarithm of the probabilities.
+     * </p>
+     * 
      * @param sequence
      *            sequences of which the logsum is calculated
@@ -101,8 +101,11 @@
      * @param validEnd
      *            if true, only sequences that finish with {@link Event#ENDEVENT} are generated
+     * @param maxIter
+     *            maximum number of attempts for the generation of the sequence; in case of failure
+     *            and empty sequence is returned
      * @return randomly generated sequence
      * 
      */
-    public List<Event> randomSequence(int maxLength, boolean validEnd);
+    public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter);
 
     /**
Index: /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieBasedModel.java
===================================================================
--- /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieBasedModel.java	(revision 2025)
+++ /trunk/autoquest-core-usageprofiles/src/main/java/de/ugoe/cs/autoquest/usageprofiles/TrieBasedModel.java	(revision 2026)
@@ -147,5 +147,5 @@
     @Override
     public List<Event> randomSequence() {
-        return randomSequence(Integer.MAX_VALUE, true);
+        return randomSequence(Integer.MAX_VALUE, true, 100);
     }
 
@@ -156,10 +156,10 @@
      */
     @Override
-    public List<Event> randomSequence(int maxLength, boolean validEnd) {
+    public List<Event> randomSequence(int maxLength, boolean validEnd, long maxIter) {
         List<Event> sequence = new LinkedList<Event>();
+        int attempts = 0;
         if (trie != null) {
             boolean endFound = false;
-            while (!endFound) { // outer loop for length checking
-                sequence = new LinkedList<Event>();
+            while (!endFound && attempts <= maxIter) { // outer loop for length checking
                 IncompleteMemory<Event> context = new IncompleteMemory<Event>(trieOrder - 1);
                 context.add(Event.STARTEVENT);
@@ -186,4 +186,8 @@
                     }
                 }
+                if (!endFound) {
+                    sequence = new LinkedList<Event>();
+                }
+                attempts++;
             }
         }
@@ -398,5 +402,5 @@
         List<Event> context = new LinkedList<Event>();
         for (Event event : sequence) {
-            odds += Math.log(getProbability(context, event)+1);
+            odds += Math.log(getProbability(context, event) + 1);
             context.add(event);
         }
Index: /trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDgenerateRandomSequences.java
===================================================================
--- /trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDgenerateRandomSequences.java	(revision 2025)
+++ /trunk/autoquest-ui-core/src/main/java/de/ugoe/cs/autoquest/commands/usage/CMDgenerateRandomSequences.java	(revision 2026)
@@ -81,5 +81,5 @@
 
 		RandomWalkGenerator generator = new RandomWalkGenerator(numSessions,
-				minLength, maxLength, validEnd, maxIter);
+				minLength, maxLength, validEnd, maxIter, 100);
 		Collection<List<Event>> sequences = generator
 				.generateTestSuite(model);
