Setting a Variable to a "random" integer w. a Variable as the maximum

Edit 3: Updated Image
Hello! Normally, I like to keep my open threads to one at a time, but my one in Script Support is taking far too long. Sorry!

I'm designing a survival game with mechanisms to prevent players from screwing around for too long. The longer the game plays, the higher "difficulty" gets, until the game is downright unfair. Part of this is the current area I'm designing, wherein NPCs leave after a certain period of time. The game reads the number of NPCs remaining as a variable, and uses that to determine with a coin flip which group of NPCs is subtracted from.

To put it more simply:
You have, for example, Group A with 10 members, and Group B with 5. The game tracks these both as variables. It adds them as 15, and chooses a random number from 1-15. If the number picked is 10 or lower, Group A loses a member, and vise versa. I want the maximum value to always reflect the number of remaining NPCs.

The problem is that this doesn't seem possible. When you set a variable to a random number, it seems you can only choose a whole number (I'm aware you can use letters, and there's even arrays, but I'm not that advanced yet.), rather than equating the minimum or maximum to another variable. I've thought of several ways around this, but all so far would ruin the accuracy of the proposed way. The only other way I see to do it is to create a Conditional for every possible maximum value, which would be extremely tedious, and difficult to adjust. Does anyone know a way around this restriction?

Spoiler: Picture of WIP Event
Random Variable Maximum.png
Moderator note: Moving
You can set your random variable like this (script option):
Control_Variables: [0009: Coin Flip] = 1 + rand($game_variables[12] - 1)

It's basically a random number between 1 and whatever variable 12 is.
rand($game_variables[12]) would return a number between 0 and 15, so I'm adding and subtracting 1 to offset this.

Problem is, once you've fallen below 11 NPCs total, group B will no longer lose members since the number will always be 10 or below.
Correct, however, 10 was just the example. It actually uses the population of group A to determine which group is picked, so no matter who loses members, it's accounted for. Thank you!

Hmm... Upon testing, it crashes. I'll play with the coding you provided a bit, see if I can get it to work.

Edit 2: I got it to work by using $game_variables[9] = 1 + rand($game_variables[12] - 1). Thanks for the help- it works beautifully now.
I'd like to add that rand(15) actually rolls a number between 0 and 14, which means you probably don't have to subtract 1 from your variable value.
Apart from that it should work fine. 🙂
Right, but I'm avoiding zero in this case. Each number corresponds to a physical NPC, so zero would be an extra digit. I don't want the code to account for an NPC that doesn't exist, you know?

In any case, it's functionally complete now. I still need to add a few sections, like making it so the "coin flip" is merely one choice the computer can use, rather than being the only choice, but I can do all that myself. Thanks for all the help.
It's not about avoiding 0, if you have a total of 11 survivors your code will yield a random number between 1 and 10 at the moment. (which means that the last survivor in the tower will always get attacked last, since rand(0) is a special case).

If you want a number between 1 and 11 instead, you should remove the -1 .
No, what I want is between 1 and 10. 10 was just the example, by the way. I'm probably going to use something closer to 15. However, I tested it just now, and it does seem unable to set the variable to 15. Since I don't understand script calling enough, I'll just trust you on this one.

Original thread: https://forums.rpgmakerweb.com/threads/setting-a-variable-to-a-random-integer-w-a-variable-as-the-maximum.82457/