<?php
// Test script to verify question order randomization
require_once 'config/database.php';

echo "=== Testing Question Order Randomization ===\n\n";

try {
    // Get questions for online exam ID 1 multiple times to check if order changes
    $online_exam_id = 1;
    
    echo "Fetching questions multiple times to check randomization:\n\n";
    
    for ($i = 1; $i <= 3; $i++) {
        $stmt = $pdo->prepare("SELECT id, question_text FROM online_exam_questions WHERE online_exam_id = ? ORDER BY RAND()");
        $stmt->execute([$online_exam_id]);
        $questions = $stmt->fetchAll();
        
        echo "Fetch $i:\n";
        foreach ($questions as $index => $question) {
            echo "  " . ($index + 1) . ". ID: " . $question['id'] . " - " . substr($question['question_text'], 0, 30) . "...\n";
        }
        echo "\n";
    }
    
    echo "✓ Question order randomization test completed\n";
    echo "If the orders are different each time, randomization is working correctly.\n";
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}
?>