Making Enemies With Varied Stat Ranges

Hey all,

I am working on stat design for my current game, and I'm at an impasse; I want to be able to add a little randomness to my enemy's stats, and I can't find out how to do this. My goal is to make an enemy have a varied bonus added to a stat I designate at the start of the battle.

I found a post on here (that I later saw was from 2015 so my reply on it will probably be denied lol) that talked about what to do with this, but it isn't working for me. The folks who gave a solution before said this is what I would add in a troop event:

for (var i = 0; i < $gameTroop.members().length; i++) {

var val = Math.randomInt(20);

var id = 2;

$gameTroop.members().addParam(id, val);

}

2 being the attack. I put this in, tested the event conditions to make sure if that was the issue and even put the stat increase at like 2000 to test it, tried changing the var id, or the var i = 0 and whatnot, and nothing is working. Any advice on what I can do here?
Feels like you're missing
Code:
[i]
Code:
for (var i = 0; i < $gameTroop.members().length; i++) {
var val = Math.randomInt(20);
var id = 2;
$gameTroop.members()[i].addParam(id, val);
}
Will this do?

Original thread: https://forums.rpgmakerweb.com/threads/making-enemies-with-varied-stat-ranges.103195/