Hello. So for my game, I'm currently working on randomized shops. When the player hits New Game, he/she is given a choice on how they want shops set up for their game, and there's a few different options. So far, I'm using this script, which randomizes a shop using a minimum item number and a max item number:
Basically, in this example, the variable 26 is set to Item type, and randomly chooses between Item 1 and Item 20 to add to the shop, with a max of 10 items total chosen for that shop. No problem, as it works fine.
My question is this: Is it possible, instead of making the variable choose between a min number and a max number, to have that same variable choose 10 random items (for example) from an array of a number of different integers? So, instead of choosing between 1 and 20, is there a way of having it choose between something like, for example, 1, 5, 13, 15, 17, 19, 21, 25, 29 and 40? I'm curious how would the code be written in this case?
Thanks in advance! Also, sorry in advance if this is in the wrong section.
JavaScript:
◆Script:var id = 26, type = 0, min = 1, max = 20, inv = 10;
: :
: :var array = [], temp = [], rand;
: :for(i = 0; i < inv; i++) {
: :do { rand = Math.floor(Math.random()*(max-min+1)+min);
: :} while (temp.indexOf(rand) > -1);
: :temp[i] = rand;
: :array[i] = [type, rand, 0];
: :}
: :if(Array.isArray($gameVariables.value(id)))
: : var array = $gameVariables.value(id).concat(array);
: :$gameVariables.setValue(id, array);
Basically, in this example, the variable 26 is set to Item type, and randomly chooses between Item 1 and Item 20 to add to the shop, with a max of 10 items total chosen for that shop. No problem, as it works fine.
My question is this: Is it possible, instead of making the variable choose between a min number and a max number, to have that same variable choose 10 random items (for example) from an array of a number of different integers? So, instead of choosing between 1 and 20, is there a way of having it choose between something like, for example, 1, 5, 13, 15, 17, 19, 21, 25, 29 and 40? I'm curious how would the code be written in this case?
Thanks in advance! Also, sorry in advance if this is in the wrong section.