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

skala
Julian Prud'homme 17 years ago
parent ae6d3a2ac9
commit 41b8451095
  1. 20
      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;

Loading…
Cancel
Save