如何在另一个php文件中引用随机数据?

I want to create a quiz-test website, where users get 5 random questions from a chosen topic, and they have to choose the correct answer from 4 answers. After that a score calculator php file tries to analyze the sent answers and to set up a score based on them. How do I check if the sent answers are the correct ones?

The database has the following structure: Every question has an ID, a question, 4 answers (A,B,C,D), a column with the correct answers indicator(so a varchart which can be only one letter) and a topic ID, which is a foreign key. After I made the test-form, I tried to refer to each randomized question differently, with the questions' index used as a hidden element, but I did not have success, the score calculator php stops working after the first correct answer and the score which is shown afterwards is not the real one, it is not correct. What should I apply?

This is my quiz form:

<form action="points.php" method="post">
        <?php
            require 'dbh.inc.php';
          $sql="SELECT * FROM questions where QuestTopic='".$_POST['topic']."' order by rand() limit 5";
          $req=mysqli_query($conn, $sql);
            $i=1;
          $_SESSION['topicchosen']=$_POST['topic'];
            while($row = mysqli_fetch_assoc($req)) {
                echo $row["Question"]."<br>";
                $rname="rn".$i;
            $rindex="rb".$i;
            $i++;
                echo "<input type='radio' name='".$rname."' value='A' checked>";
                echo $row["AnsA"]."<br>";
                echo "<input type='radio' name='".$rname."' value='B'>";
                echo $row["AnsB"]."<br>";
                echo "<input type='radio' name='".$rname."' value='C'>";
                echo $row["AnsC"]."<br>";
                echo "<input type='radio' name='".$rname."' value='D'>";
                echo $row["AnsD"]."<br>";
            echo "<input type='hidden' name='".$rindex."' value='".$row["QuestNum"]."'>";
          }
            $conn->close();
        ?>

And this is my point calculator

  include "dbh.inc.php";
                            $sql="SELECT * FROM questions where QuestTopic='".$_SESSION['topicchosen']."'";
                            $req=mysqli_query($conn, $sql);
                            $points=0;
                            $i=1;
                            while ($row=mysqli_fetch_assoc($req)){
                                    $rname="rn".$i;
                                    $rindex="rb".$i;
                                    if($_POST[$rindex]==$row['QuestNum']) {
                                      if ($_POST[$rname]==$row['CorrectAns']) {
                                          $points+=5;
                                        }
                                        $i++;
                                      }
                            }

                            echo $points;