从randomize数组中仅显示特定数量的问题

the randomize function is working fine with shuffle array of question. how can we pick specific amount by 'N' numbers to remove from the array each time when randomize works. Means if we wish to show 20% or 20 questions from a list of 100 questions each time in randomize mode

public function random_questions( $quiz_questions, $quiz_id ) {
    if ( get_post_meta( $quiz_id, '_lp_random_mode', true ) == 'yes' ) {
        // get user meta random quiz
        $random_quiz = get_user_meta( get_current_user_id(), 'random_quiz', true );
        if ( is_admin() || empty( $random_quiz ) || empty( $random_quiz[ $quiz_id ] ) ) {
            return $quiz_questions;
        }
        $questions = array();
        if ( array_key_exists( $quiz_id, $random_quiz ) && sizeof( $random_quiz[ $quiz_id ] ) == sizeof( $quiz_questions ) ) {
            foreach ( $random_quiz[ $quiz_id ] as $question_id ) {
                if ( $question_id ) {
                    $questions[ $question_id ] = $question_id;
                }
            }
        } else {
            $question_ids = array_keys( $quiz_questions );
            shuffle( $question_ids );
            $random_quiz[ $quiz_id ] = $question_ids;
            $questions               = array();
            foreach ( $question_ids as $id ) {
                $questions[ $id ] = $quiz_questions[ $id ];
            }
        }
        return $questions;
    }
    return $quiz_questions;
}

Use array_rand() to get a random selection of array keys, instead of using all the keys with array_keys(). Then it's not necessary to shuffle the array.

        $question_ids = array_rand( $quiz_questions , 20);
        $random_quiz[ $quiz_id ] = $question_ids;
        $questions               = array();
        foreach ( $question_ids as $id ) {
            $questions[ $id ] = $quiz_questions[ $id ];
        }