Complex Random Choices (how to pick 4 of 7 randomly)

Context: my game will have 10 mentor characters scripted as quest-givers. Which mentor you interact with will drastically change your character and story progression. Now, out of these 10, I want only 7 to be available per playthrough. This will make each playthrough a bit different. 3 of them are given priority and will always be available. This means I'd like 4 of the remaining 7 to be chosen at random.

I know how to randomize single variables using parallel events, but how can I ensure that 4 unique choices are randomized out of the 7?

Any help is greatly appreciated!
I have no idea how you're organizing what mentors are available, but as a general answer...put this in a Script box in an event:
Code:
var mentors[4, 5, 6, 7, 8, 9, 10];
var index=Math.randomInt(mentors.length);

$gameVariables.setValue(X, mentors[index]);
mentors.splice(index);

index=Math.randomInt(mentors.length);
$gameVariables.setValue(Y, mentors[index]);
mentors.splice(index);

index=Math.randomInt(mentors.length);
$gameVariables.setValue(Z, mentors[index]);

where X, Y, and Z are the IDs of 3 game variables. Those variables will then have three unique numbers of mentors to use, from 4-10.
I was going to suggest a way to do this with an event, but ATT_Turan's approach is actually a lot more streamlined and saves you using up a whole set of switches. Still, I figured I'd say something just in case you prefer this way. Basically, I'd do it like the screenshot below, just use the same format for the other mentors you can't see in the event.

It's not the only or best way to event this, but it would work and it's pretty simple. Hopefully one of us got you where you need to be 🙂

Spoiler: randomizer event
Screenshot (187).png
You could do it in an event without any switches, and just use a few loops.

Code:
Variable 1 = random number from 4-10
Loop
  Variable 2 = random number from 4-10
   Conditional Branch -> Variable 2 is not equal to variable 1?
       Break Loop
End
Loop
   Variable 3 = random number from 4-10
   Conditional Branch -> Variable 3 is not equal to variable 1?
        Conditional Branch -> Variable 3 is not equal to variable 2?
            Break Loop
End

You'll still use only 3 variables and end up with 3 unique values from 4-10, it's just a bit less efficient than the script box.
Thank you both @ATT_Turan and @BenSD!
That first script should do just fine for what I need, but I appreciate the alternatives in case I get snagged in implementation.
Hello @Bokeh. Since you intended to use what you call the first script you should know of certain issues it will have once you start testing it.
Thank you both @ATT_Turan and @BenSD!
That first script should do just fine for what I need, but I appreciate the alternatives in case I get snagged in implementation.
The idea is correct but the code itself is wrong.
Code:
var mentors[4, 5, 6, 7, 8, 9, 10];
This will give you a syntax error. This is probably just an oversight. If not corrected the code will still run but you'll get weird values and a script call error if you press F8 during playtesting.
Code:
mentors.splice(index);
This will delete all elements in the mentors array starting from index. For example, if index === 3, i.e. 7 then mentors will become equal to [4, 5, 6]. If index === 0, i.e. 4 then mentors will become empty and, assuming 4 isn't the last variable value, subsequent values will give you zero (0) which will in turn give you errors when you try to match zero with actor IDs.

Assuming the syntax error had been correctly written and everything else kept as is, the code from that script call will run without errors but you'll notice the following:

Spoiler: Playtesting Behavior
  1. If 5 isn't the last variable it will always be followed by 4.
  2. If 5 is the first variable or 4 is either the first or second variable you will always get at least one 0.
  3. If you get anything else you'll notice the values you get are ALWAYS strictly decreasing i.e. X > Y > Z. As mentioned above, this is due to mentors.splice(index);.
  4. The code was meant for three (3) rather than four (4) randomly selected elements from the mentors array.

If the above behaviors are acceptable to you then you just need to correct the array declaration code var mentors[4, 5, 6, 7, 8, 9, 10]; in the first script call.

If you want to properly accomplish what you intended in your first post, i.e. random selection without replacement of 4 items out of a pool of 7, then you should use instead the code below in your script call:
Spoiler: Code
JavaScript:
var cv = [21, 22, 23, 24]; // replace these
var mentors = [4, 5, 6, 7, 8, 9, 10];
var index = Math.randomInt(mentors.length);
for (var i = 0; i < cv.length; i++) {
  $gameVariables.setValue(cv[i], mentors[index]);
  if (i < cv.length - 1) {
    mentors.splice(index, 1);
    index = Math.randomInt(mentors.length);
  }
}
The above code is mostly copy and paste. Just replace 21, 22, 23 and 24 within the first line cv = [21, 22, 23, 24]; with the IDs of your control variables containing the actor IDs of the four (4) non-priority actor mentors from 4 to 10.
Alternative:
JavaScript:
var ids    = [10, 11, 12, 13];        // game variable IDs
var values = [1, 2, 3, 4, 5, 6, 7];   // values to select
var i = 0;
for (var n = ids.length; n--;) {
  if (!values.length) break;
  i = Math.randomInt(values.length);
  $gameVariables.setValue(ids[n], values.splice(i, 1)[0]);
}
More technical information here:
Alternative:
JavaScript:
var ids    = [10, 11, 12, 13];        // game variable IDs
var values = [1, 2, 3, 4, 5, 6, 7];   // values to select
var i = 0;
for (var n = ids.length; n--;) {
  if (!values.length) break;
  i = Math.randomInt(values.length);
  $gameVariables.setValue(ids[n], values.splice(i, 1)[0]);
}
More technical information here:
This code is just beautiful. 😍And better. 😂

Original thread: https://forums.rpgmakerweb.com/threads/complex-random-choices-how-to-pick-4-of-7-randomly.146463/