how to learn random skills

Perhaps My language is unclear each book there's a list of learnable spells you read a book by consuming it and learn from a list of 20 spells
Example Crimson book (fire spells)
1Fire Bolt
2Dragon Breath
3Demon Fire
4)Flaming Wings
5)Fire Seeds
6)Towering Inferno
7)Cremate
8)Flamethrower
9)Inferno
10)Waterfall of Flames
11)Molotov Cocktail
12)Hellfire
13)Flash
14)Flamenwaffer
15)Dragon Fire
16)Wings of Hell
17)Fireball
18)Incendiary Cloud
19)Napalm
20)Flames of Hell
bump😉
You would write a random value 1-20 into a variable and then do 20 conditional branches, if the variable is 1 you teach Fire Bolt, if it's 2 you teach Dragon Breath, and so on.

This gets a bit more complicated if you want to make sure the hero will only learn a skill they don't already know - this case I'd say the easiest way would be to put the whole thing in a loop, and instead of just teaching each skill you would use another condition inside each condition to check whether the skill was already learned, and only if no you teach it and break the loop. This way it would just try again and again random skills until it finds one that can be learned.

To avoid getting the game stuck in an infinite loop if all 20 skills are already known, you'd then add a condition before everything else where you basically nest 20 conditions that check for each skill, so only if all 20 are true (skills known), you would then show some message that there is nothing left to learn and exit.

Pseudocode:

Code:
if hero knows skill A
  if hero knows skill B
    if hero knows skill C
      ...
      ...
      ...
        if hero knows skill T
          show message: "nothing to learn"!
          end event processing
        : end
      ...
      ...
      ...
    : end
  : end
: end

label 1

change variable SKILL_NUM = random (1...20)

if SKILL_NUM == 1
  if hero knows skill A
    go to label 1
  : else
    teach hero skill A
  : end
: end

if SKILL_NUM == 2
  if hero knows skill B
    go to label 1
  : else
    teach hero skill B
  : end
: end

if SKILL_NUM == 3
  if hero knows skill C
    go to label 1
  : else
    teach hero skill C
  : end
: end

...
...
...

if SKILL_NUM == 20
  if hero knows skill T
    go to label 1
  : else
    teach hero skill T
  : end
: end

Here instead of a loop command and breaking the loop after teaching, I used a label at the start of the code to create the loop in order to make it shorter (because we can jump to it in one case and learn the skill in the other, instead of having an awkward empty case first and then both the breaking and the teaching in the "else").

Original thread: https://forums.rpgmakerweb.com/threads/how-to-learn-random-skills.116951/