public static function get_random_question_summaries(
        $categoryid,
        $includesubcategories,
        $tagids,
        $contextid,
        $limit = 0,
        $offset = 0
    ) {
        global $DB, $PAGE;

        // Parameter validation.
        $params = self::validate_parameters(
            self::get_random_question_summaries_parameters(),
            [
                'categoryid' => $categoryid,
                'includesubcategories' => $includesubcategories,
                'tagids' => $tagids,
                'contextid' => $contextid,
                'limit' => $limit,
                'offset' => $offset
            ]
        );
        $categoryid = $params['categoryid'];
        $includesubcategories = $params['includesubcategories'];
        $tagids = $params['tagids'];
        $contextid = $params['contextid'];
        $limit = $params['limit'];
        $offset = $params['offset'];

        $context = \context::instance_by_id($contextid);
        self::validate_context($context);

        $categorycontextid = $DB->get_field('question_categories', 'contextid', ['id' => $categoryid], MUST_EXIST);
        $categorycontext = \context::instance_by_id($categorycontextid);
        $editcontexts = new \question_edit_contexts($categorycontext);
        // The user must be able to view all questions in the category that they are requesting.
        $editcontexts->require_cap('moodle/question:viewall');

        $loader = new \core_question\bank\random_question_loader(new qubaid_list([]));
        // Only load the properties we require from the DB.
        $properties = \core_question\external\question_summary_exporter::get_mandatory_properties();
        $questions = $loader->get_questions($categoryid, $includesubcategories, $tagids, $limit, $offset, $properties);
        $totalcount = $loader->count_questions($categoryid, $includesubcategories, $tagids);
        $renderer = $PAGE->get_renderer('core');

        $formattedquestions = array_map(function($question) use ($context, $renderer) {
            $exporter = new \core_question\external\question_summary_exporter($question, ['context' => $context]);
            return $exporter->export($renderer);
        }, $questions);

        return [
            'totalcount' => $totalcount,
            'questions' => $formattedquestions
        ];
    }