Basing A Range Maximum on a Variable

Long story short, I want the game to pick a number between 1 and the value of another variable that changes randomly depending on what happens in the game.

For example, let's say the events of the game cause Variable A to equal 6. I then want the game to choose a random number between 1 and the value of Variable A. Because Variable A's value is always random, I want to be able to set the max range for a random number to be equal to whatever Variable A is.

Is this possible?
You can use Control Variables -> Script: min + Math.randomInt(max - min + 1)

E.g. for a range 1 to {variable ID 5} inclusive, it would be:
JavaScript:
1 + Math.randomInt($gameVariables.value(5))
Just replace 5 with the ID of "variable A".

Original thread: https://forums.rpgmakerweb.com/threads/basing-a-range-maximum-on-a-variable.177367/