MZ Random Number Between Several Arrays

Hey all,

I am trying to make a common event for random fetch quests. To do this, I want to set the item needed to be random. Usually I would just set my temporary variable to the equal the item number. However, I do not want to include all item numbers. How would I set a JS function to be between several number arrays? (eg. 1-60, 70-90, 61, 65).
You can use an array in a script call:

Code:
var x = #
var itemchoice = [1, 2, 3, 4, 5];
var index = Math.randomInt(itemchoice.length);
var questitem = itemchoice[index];
$gameVariables.setValue(x, questitem);

  1. Set x to the game variable you wish to store the result under
  2. Inside the square brackets [ ], type each number followed by a comma. It will be a long list, but it's guaranteed to work.
There is also a method called splice in JavaScript. If you wish to look into how to utilize it, feel free. This array, set up correctly, will function the same.
In general I think I'd consider an array, too. However, unless you have a lot of gaps, this shouldn't be too bad without scripting. You can roll a random number for the full range, and add values to bump it over the gaps you want to skip.

For your example:
(eg. 1-60, 70-90, 61, 65).
The full range is 60 + 21 + 1 + 1 = 83, with only two gaps:
  • 62~64 inclusive => +3 (62 -> 65) if rolled value ≥ 62;
  • 66~69 inclusive => +4 (66 -> 70) if rolled value ≥ 66.
E.g.

◆Control Variables:#0001 = Random 1..83 ◆If:#0001 ≥ 62 ◆Control Variables:#0001 += 3 ◆ :End ◆If:#0001 ≥ 66 ◆Control Variables:#0001 += 4 ◆ :End ◆Text:None, None, Window, Bottom : :Random pick: \v[1]

Original thread: https://forums.rpgmakerweb.com/threads/random-number-between-several-arrays.156332/