ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilTestShuffler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
30 {
32 
33  public function __construct(
34  protected Refinery $refinery
35  ) {
36  }
37 
38  public function getAnswerShuffleFor(
39  int $question_id,
40  int $active_id,
41  int $pass_id
43  $fixedSeed = $this->buildFixedShufflerSeed($question_id, $pass_id, $active_id);
44  return $this->refinery->random()->shuffleArray(new GivenSeed($fixedSeed));
45  }
46 
47  protected function buildFixedShufflerSeed(int $question_id, int $pass_id, int $active_id): int
48  {
49  $seed = ($question_id + $pass_id) * $active_id;
50  if (is_float($seed) && is_float($seed = $active_id + $pass_id)) {
51  $seed = $active_id;
52  }
53 
54  $div = ceil((10 ** (self::FIXED_SHUFFLER_SEED_MIN_LENGTH - 1)) / $seed);
55  if ($div > 1) {
56  $seed = $seed * ($div + $seed % 10);
57  }
58  return (int) $seed;
59  }
60 }
buildFixedShufflerSeed(int $question_id, int $pass_id, int $active_id)
const FIXED_SHUFFLER_SEED_MIN_LENGTH
getAnswerShuffleFor(int $question_id, int $active_id, int $pass_id)
__construct(protected Refinery $refinery)