Browse Source

[svn r15939] Fix a possible bug (if a user choose a number of random question > total number of questions of the test)

Julian Prud'homme 16 years ago
parent
commit
41b8451095
1 changed files with 11 additions and 9 deletions
  1. 11 9
      main/exercice/exercise.class.php

+ 11 - 9
main/exercice/exercise.class.php

@@ -25,7 +25,7 @@
 *	Exercise class: This class allows to instantiate an object of type Exercise
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: exercise.class.php 15938 2008-08-07 08:50:05Z elixir_julian $
+* 	@version $Id: exercise.class.php 15939 2008-08-07 09:01:09Z elixir_julian $
 */
 
 
@@ -265,15 +265,17 @@ class Exercise
 		$alreadyChosen = array();
 		
 		for($i=0; $i < $this->random; $i++)
-		{			
-			do
-			{
-				$rand=rand(1,$nbQuestions);
+		{	
+			if($i < $nbQuestions){
+				do
+				{
+					$rand=rand(1,$nbQuestions);
+				}
+				while(in_array($rand,$alreadyChosen));
+				
+				$alreadyChosen[]=$rand;
+				$randQuestionList[$rand] = $this->questionList[$rand];
 			}
-			while(in_array($rand,$alreadyChosen));
-			
-			$alreadyChosen[]=$rand;
-			$randQuestionList[$rand] = $this->questionList[$rand];		
 		}
 
 		return $randQuestionList;