What if you create a variable array (unit-type) so you can store which units are available for training, then you add another integer variable (let's call it "count") to count how many units a player or computer may order to train it. Then, in the function "random number between", you put "1 and the count variable", and use the unit-type variable in the training function. Of course, you'd have to make another trigger detecting when a player/computer builds/upgrades their base so that they're be able to train such units. (As you know, barracks for both footman and rifleman, but rifleman needs the black smith).