Here’s what you’d need.

- An array of strings representing the math equation
- (Assuming your game has a bank of preset equations to choose from) - a corresponding array of correct answers to the equation, stored at the corresponding index to their question
- An RNG so the equation can be posted randomly.

Once you have those, you’ll want to first generate the random number, something between zero and the size of your array minus one (remember array index starts at 0), then you store that number for later.

Next, When you arrive at the point in space that you want to ask the question, set your UI element’s text component to be your array of math equation strings at the index of the number you generated earlier, then, display the answer from the correct answers array by choosing the index of the same number as your equation.

Next, choose two more (or however many incorrect answers you want to show) random numbers between zero and your array length minus one. Do a quick check that neither of the random number’s generated match your first generated number, if they do, generate them again (you don’t want the correct answer displayed twice).

Next, Generate a number between 1 and x ( x being the number of possible answers you want displayed) - this will be where your correct answer is displayed. It doesn’t matter where the other answers are displayed because they are wrong/randomly chosen already. You should have an array of positions where to display the answers, so display the correct answer at the index of the most recently generated number. Continue to place the rest of the incorrect answers, filling in to the left of the first answer’s placement (if possible), then to the right(if possible).

The correct answer should be marked as such when it is first chosen out of the array, and so checking it should require a simple boolean check as soon as an element is clicked. Upon clicking, if the check returned true, run a continue function, otherwise, run a restart function.

This is conceptually how I would do it were I in your position. It is a very simple implementation with C#, and if you know the foundation, it shouldn’t be difficult. If you have no foundation in C# or Java, I would strongly recommend you obtain one before trying to tackle a logic based project like this.