skill targeting exact or less number of enemy/enemies without repeating

i want to make a skill that
for example:
- here is a skill deals damage to 3 random enemies. If there are 8 enemies in a troop, the skill targets random 3 enemies without repeating damage to 1 or 2 enemies. Also if there are only 1 or 2 enemies in a troop, which is less than a number of targets(3 enemies to attack without repeating) of the skill, the skill doesn't need to damage random 3 enemies with repeating, instead the skill damages to 1 or 2 enemies without repeating, which is an exact number of enemies in a troop.

I can guess that this can handle with yanfly's target&selection plugin, but I'm not good at javascript, so can someone help me with this situation?
I believe you're lookin for this:

Indeed, to use this skill you'll need Yanfly's Target Core and Damage Core plugins.
Paste this on your skills notebox. Set the scope to all enemies.

Code:
<Custom Target Eval>
targets.push(target);
var members = foes.aliveMembers();
members.splice(members.indexOf(target), 1);
//This is the numer of extra enemies the skill will hit! this case is 1 + 2
var extraTargets = 2;
while (extraTargets--) {
  var member = members[Math.floor(Math.random() * members.length)];
  if (member) {
    targets.push(member);
    members.splice(members.indexOf(member), 1);
  }
}
</Custom Target Eval>
thank you 🙂 your note code works really well!! 🙂

Original thread: https://forums.rpgmakerweb.com/threads/skill-targeting-exact-or-less-number-of-enemy-enemies-without-repeating.96199/