How to roll random value at the end of a turn

Hello,

I want to set a variable [n] as a random value, ranging between [x] and [y].

I tried to set the V[n] in a troop event (end of turn):

"Math.floor( Math.random() * ($gameVariables.value(y) - $gameVariables.value(x) + 1 )) + $gameVariables.value(x)"

Then I put the V[n] into a damage formula.

At last, I started the game and tested the battle.

After the first turn, the game crashed.

So anyone knows what's wrong?

Thanks.
Why not just use the random value portion of the Control Variables event command?

In the damage formula, it's lower case v[n], not V.

I don't see anything in your troop event code that looks like it would produce a crash, presuming you correctly put actual IDs and not x and y.
The problem solved. YEP SkillCostItems caused a conflict, and I turn it off.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-roll-random-value-at-the-end-of-a-turn.159212/