Ok, that makes it easier.
We'll start with a list of ALL actors which kind of already exists as $dataActors. This is an array of objects. Each object contains the data for each Actor in the database.
It kind of looks like this: [null, (Actor1 data), (Actor2 data), (Actor3 data)...]
But we don't want that "null" object because it doesn't have any properties so we are going to start a new array without it.
JavaScript:
list = $dataActors.slice(1);
Now we have an array (named "list") with all the actors and their data. And we're going to start filtering out Actors. I'm going to assume any Actor in the database that doesn't have a name is just a blank space to be omitted from the selection pool.
JavaScript:
list = $dataActors.slice(1);
list = list.filter(element=>element.name.length > 0)
So now "list" is a more usable pool of Actors to randomly select from. It's not that different from the array of numbers you started with in the script posted above. Only instead of numbers it's an array of objects with properties (name, id, metadata) for each actor. It's just more to work with. If you add more Actors to the database in the future then they'll automatically be included.
So for your first party member, maybe it doesn't matter who it is. We'll just pick a random number between 1 and list.length
JavaScript:
list = $dataActors.slice(1);
list = list.filter(element=>element.name.length > 0)
ranN = Math.randomInt(list.length)
$gameVariables.setValue(1, list[ranN].id)
We're storing the actor Id number in game Variable#1, but we could also set it to .name instead so you could easily display \v[1] in your quest requirement details.
On to random party member #2. Because you have factions we'll need to filter the list again based on the data of member #1. I have no idea how many factions there or what their relationships might be. So for this example I'm just going to assume you have "Good" and "Evil", where neither will party up together normally.
This will require you to enter a "faction" as meta data within the Actor's Notebox. Just enter as <good> or <evil> or maybe <faction:good> <faction:evil>
It's a matter of personal taste.
JavaScript:
if (list[ranN].meta.faction == "good"){list = list.filter(element=>element.meta.faction != "evil")}
list.filter(element=>element.id != list[ranN].id)
If #1 is Good, then #2 can't be Evil. We've filter all the "Evil" actors from the list. Before randomly selecting another character we should also filter #1 from the pool so they won't be selected twice.
note: might be a careful to chain multiple if statements with an "else" so it's all processed once. I don't want to fudge up my example by adding on to it at this point. Some trouble shooting will be inevitable.
This should get you somewhere
Try it out for yourself.
JavaScript:
list = $dataActors.slice(1);
list = list.filter(element=>element.name.length > 0)
ranN = Math.randomInt(list.length)
$gameVariables.setValue(1, list[ranN].id)
if (list[ranN].meta.faction == "good"){list = list.filter(element=>element.meta.faction != "evil")}
list = list.filter(element=>element.id != $gameVariables._data[1])
ranN_two = Math.randomInt(list.length)
$gameVariables.setValue(2, list[ranN_two].id)
[img]https://i.imgur.com/vFGvFce.png[/img]
When it comes to the quest start confirmation. You can use a conditional branch script to check the party.
I think storing .id rather than the .name might make this easier. Since $gameParty._actors is just an array of actor ids like [1,3,6,7]
JavaScript:
$gameParty._actors.includes($gameVariables._data[1])
But we can convert these numbers to names with another script, and see if the party member names match the text string stored in the variable
JavaScript:
wName= [];
$gameParty._actors.forEach(element => wName.push($dataActors[element].name));
if (wName.includes($gameVariables._data[1])) {window.alert("variable name 1 confirmed in party")};
Maybe flip a switch or something in confirmation
Edit: I wrote this in MZ but tested in MV to make sure there wasn't some oversight. It should still work. However, don't try to use this if none of the Actors in the database have names. Or if there aren't any/enough actors in the list to select. It'll throw errors trying to read properties of an empty list. There's no failsafe saying "hey, there aren't any other actors to select for #2. Go back."
Depending on how you filter factions, that might be a problem.