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 1996)
+++ 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 1996)
+++ 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);
         }
