public static function init($number, array $categories, $path)
{
$data = self::prepareFromYaml($categories, $path);
if (!$data) {
return new Set(array());
}
$dataMax = count($data) - 1;
$questions = array();
for ($i = 0; $i < $number; $i++) {
do {
$random = rand(0, $dataMax);
} while (isset($questions[$random]) && count($questions) < $dataMax);
$item = $data[$random];
$answers = array();
foreach ($item['answers'] as $dataAnswer) {
$answers[] = new Answer($dataAnswer['value'], $dataAnswer['correct']);
}
if (!isset($item['shuffle']) || true === $item['shuffle']) {
shuffle($answers);
}
$questions[$random] = new Question($item['question'], $item['category'], $answers);
}
return new Set($questions);
}