Random number - range from varA to varB

fizzly

Veteran
Veteran
Joined
Mar 23, 2012
Messages
509
Reaction score
331
First Language
Polish
Primarily Uses
RMMV
Hello,
can someone help me with the javascript? I need a piece of script that can choose a random number from a range, but I want to input a range from variables, so for example, varA is 1, barB is 7, then it can randomize a number from 1 to 7.
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
386
Reaction score
204
First Language
English
Primarily Uses
RMMV
I'm not sure where you want to use it, but the last line in the below code will be a random number between varA and varB.

JavaScript:
var a = $gameVariables.value(idA); //replace idA with ID of varA
var b = $gameVariables.value(idB); //replace idB with ID of varB
a + Math.randomInt(b-a);
Hopefully you can shimmy it around to suit your needs if necessary. :)
 

Soulrender

Veteran
Veteran
Joined
Jan 12, 2019
Messages
402
Reaction score
232
First Language
Poland
Primarily Uses
RMMV
Or this:
Code:
GenerateRandomNumber = function(min, max){
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
 

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

Latest Threads

Latest Posts

Latest Profile Posts

It's weird I actually have MORE work to do when stuck at home than before.
The No Travel Game Jam is here! Jump in to make a game in the month of April that takes place all in one town!


Decided to take a stab at video editing.... Even made a clickbait screen. I'm so proud of my sellout ways. :LZSexcite:

Forum statistics

Threads
95,470
Messages
929,397
Members
125,712
Latest member
Flane
Top