Math database...?

Hi everybody, hope you all are fine.
I need some help or a good idea on how to arrange a database in my game.
In my game, battles are made so that the player have to answer a question in order to play the turn, otherwise it will be blocked until next turn/question.
I stored all the questions in a "Question Database Common Event", called during battles. In detail, at the beginning of the game a "Question Variable" is set to 1; then, during battles, the "Question Database Common Event" is called, in it the questions are packed in "If... then" statements, so that If [Question Variable] is 1 then the first question appears. At the end of the turn, a +1 is added to the "Question Variable", so the next turn the question will be the number 2, and so on. (Hope the explanation is understandable).
What I want is to shuffle the question order in different games: I don't want the game to repeat the same identical question order. I could use random numbers, but there is the risk to have a question repeated many times, and I want to avoid that, too.
Is there a possibility to use a random-variable system, but excluding the numbers/questions already used? Like storing them in an array, and subtracting them to the numbers that can be selected?
I thought of this during the last days, but couldn't find a way to do that, so here I am.
Any suggestion?
Thanks in advice, and greetings from Italy
Ah, I knew I'd written something about this fairly recently~
There are various options discussed here:
My suggestion would be something like this:

◆If:Script:!$gameVariables.value(123).length ◆Comment:No numbers remaining in list, or not initialised yet. ◆Control Variables:#0123 Jokes = Array.from(new Array(140), function(_, n) { return 1 + n; }) ◆ :End ◆Comment:Take a random number out of the array and store in variable 2. ◆Control Variables:#0002 JokeID = var a = $gameVariables.value(123); a.splice(Math.randomInt(a.length), 1)[0] ◆Text:None, Window, Bottom : :Selected joke \v[2]!
Easy-copy versions for the Script fields:
JavaScript:
!$gameVariables.value(123).length
JavaScript:
Array.from(new Array(140), function(_, n) { return 1 + n; })
JavaScript:
var a = $gameVariables.value(123); a.splice(Math.randomInt(a.length), 1)[0]
Substitutions:
  • Replace 123 with the ID of the variable where you want to store the list of remaining joke IDs.
  • Replace 140 with the total number of jokes you have.
  • Replace the Show Text at the end with 1 branch per joke ID, e.g.
    • If joke ID is 1: "Why did the chicken cross the road";
    • If joke ID is 2: "Knock knock";
    • Etc.
Hope that helps! 👋
Ah, I knew I'd written something about this fairly recently~

Hope that helps! 👋

Hey @caethyril many thanks for the super-fast reply!
Your system seems the best, I'll rearrange my database to test it asap and I'll let you know!
Meanwhile, many thanks again!!
You're welcome, good luck!
Hey @caethyril, just tried it, it works! Many, many thanks!
If I want it to start from the beginning in case all of the numbers are chosen, how can it be modified?
Great! 😂

The example I gave should automatically re-initialise the array of numbers if it becomes empty:

◆If:Script:!$gameVariables.value(123).length ◆Comment:No numbers remaining in list, or not initialised yet. ◆Control Variables:#0123 Jokes = Array.from(new Array(140), function(_, n) { return 1 + n; }) ◆ :End
This is the condition:
JavaScript:
!$gameVariables.value(123).length
It means "the length of the value of variable ID 123 is not truthy". This is true when:
  1. "Not initialised yet": the value does not have a length property (e.g. any number); or
  2. "No numbers remaining in list": the value is an array with length 0.
Sorry I bother you for nothing, I could have figured it out by myself, it was clearly specified...
Many thanks again, this will improve a lot my game!
Grettings and happy new year from Italy!
No worries, happy RPG Making! 👋

Original thread: https://forums.rpgmakerweb.com/threads/math-database.164213/