ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestShuffler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
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}
Builds data types.
Definition: Factory.php:36
buildFixedShufflerSeed(int $question_id, int $pass_id, int $active_id)
__construct(protected Refinery $refinery)
const FIXED_SHUFFLER_SEED_MIN_LENGTH
getAnswerShuffleFor(int $question_id, int $active_id, int $pass_id)