How to roll a random number between two variables

wickednick

Veteran
Veteran
Joined
Feb 19, 2016
Messages
65
Reaction score
3
First Language
Nick
Primarily Uses
So I want to roll a random number between two variables for encounters. I found this script on the forums but I can't seem to get it to work.

$gameVariables.value(13);

$gameVariables.value(14);

Math.random();

Math.min(13, 14) + rd * Math.abs(14 - 13);

$gameVariables.setValue(11, value);

thanks
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
782
Reaction score
422
First Language
Poland
Primarily Uses
RMMV
use this:

Math.floor(Math.random() * (max - min + 1)) + min;

put in place of max and min your variables and set it as value to your variable #11
 

wickednick

Veteran
Veteran
Joined
Feb 19, 2016
Messages
65
Reaction score
3
First Language
Nick
Primarily Uses
Thanks a bunch. I tried making something like that, but couldn't figure it out and the script I found seemed overly complicated for what I wanted to do.
 

wickednick

Veteran
Veteran
Joined
Feb 19, 2016
Messages
65
Reaction score
3
First Language
Nick
Primarily Uses
So I had to modify it a bit to get it to work like I wanted so it would actually pull the numbers from the two variables. Thanks again.
Math.floor(Math.random() * ($gameVariables.value(14) - $gameVariables.value(13) + 1))+$gameVariables.value(13);
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Woke up on an awful nightmare of being banned here because some mod didn't liked me in a super-heroes freeform round robin RP where I used throwing normal hammer as power and it was qualified being too OP. XD Nice to read you all guys. Will not wait next nightmares.
Staring at all the RPG Maker versions I have and realizing that my project has been a long time coming. But, I finally feel like I have the knowledge and experience to make it into something good.
We're almost done with the jam game! :D

Forum statistics

Threads
104,324
Messages
1,005,564
Members
135,845
Latest member
lguruji206
Top