Randomizing a Map with Premade rooms?

And that's fine for you, but the OP has stated their personal knowledge and preference.

They are right in this sense. I picked up RPG maker on the grounds of the advert of not needing to know how to code. I'm an artist first and foremost, while I'm open to learning to code I am a complete novice. I can't "hello world" myself out of a cardboard box.... yet! I hope to one day learn but I also want to move forward in my project. So this solution is great for my short game project.


I totally agree, I was going to point out to your eventing solution, but was caught in my scripting logic.

RPG Maker is user friendly and does not require one to have scripting logic/knowledge, however understanding how scripting works will help to make better events (even without scripts).

I just tried to give a condensed script (I can't think of something simpler), especially since OP seem to have somewhat interest in extending his knowledge. 🙂

Again,I agree that, without proper knowledge, my script probably looks like magic or alien stuff. 😊

This is why I appreciated you taking the time to explain the script. It's still very alien but as I learn I can come back to this thread and re-read the information until I fully understand it and then in a later project I can utilize this solution.
Eventing is a form of programming. There is a lot of carry-over to scripting ^^

It's nice to learn about different solutions. Having different perspectives often helps when figuring out how to overcome a technical hurdle.
ATT_Turan solution is simple to understand and simple to implement, but scales poorly. My version is more advanced but scales better.

Consider you have 20 maps instead of 6 maps. All you need to do is to changing the Map end ID and random range.
1721996059019.png


If you use the pure eventing solution you'd also need to expand on the Map use lookup and Set map used
1721996339831.png

Compare this to how each extra loop requires progressively more checks
1721996719344.png

Beyond more checks it also takes more rolls on average to find the last number. Here with 20, the last number will take about about 14-15 rolls on average to find the last number. When you have 6 maps it'll take about 4 rolls on average.
It not being a good solution with 20 maps doesn't mean that it's a bad solution with 6 maps. I hope this helps you understand the two evented solutions better ^^


For bonus info here is a way of doing things with script calls. Firstly we have an init event shuffle the list of numbers. We do this by abusing JavaScript's array sort function.
1721998582699.png

Code:
JavaScript:
// Setup map ids or index here - Ensure this array does not contain 0
$mapIds = [1, 2, 3, 4, 5, 6];
// Shuffle
$mapIds = $mapIds.sort(() => Math.random() - 0.5);

Next we use the script section of set variables to get a number:
1721998779540.png


When $mapIds is empty the variable be set to 0. This is the reason why $mapIds must not contain any 0s
1721998905653.png


Good luck with your project.

*hugs*
- Zeriab
For bonus info here is a way of doing things with script calls. Firstly we have an init event shuffle the list of numbers. We do this by abusing JavaScript's array sort function.
View attachment 312636
Code:
JavaScript:
// Setup map ids or index here - Ensure this array does not contain 0
$mapIds = [1, 2, 3, 4, 5, 6];
// Shuffle
$mapIds = $mapIds.sort(() => Math.random() - 0.5);

Do note that that "shuffle" is inefficient and biased - if you care about the results being truly random, you're better off using something like the Fisher-Yates algorithm. Check out the discussions here: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array and here: https://javascript.info/array-methods#shuffle-an-array
Interesting points. Let's check them out and see how they fare.
Note: I will be using this Fisher-Yates implementation which I got from @bass2yang
JavaScript:
function shuffleArray(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    const temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
}

Performance
Here are the two methods I use for running the two types of shuffles a bunch of times:
JavaScript:
function shuffleArrayFisherYates(start, times) {
  array = start.clone();
  for (let t = 0; t < times; t++) {
    for (let i = array.length - 1; i > 0; i--) {
      const j = Math.floor(Math.random() * (i + 1));
      const temp = array[i];
      array[i] = array[j];
      array[j] = temp;
    }
  }
}

function shuffleArrayViaSort(start, times) {
  array = start.clone();
  for (let t = 0; t < times; t++) {
    array.sort(() => Math.random() - 0.5);
  }
}

I open up the DevTools when running an RPG Maker MV project start recording
1722151267510.png


Then I run the following code in the console, after which I stop the profiling.
$array = [1,2,3,4,5,6];
times = 1000000;
shuffleArrayFisherYates($array, times);
shuffleArrayViaSort($array, times);

The resulting running time were:
Fisher-Yates: 67ms
Sync sort: 332ms

I repeated the experiement a couple of times (each with an array of 6 elements) and the outcome was consistent with Sync being 5 times slower than Fisher-Yates.
Notice that we are shuffling a million times. This means that we can expect the actual time save of switching from Sync sort to Fisher-Yates to be less than 1 microsecond, a neglible difference.
In conclusion, in our context of a single shuffle of 6 elements, both Sync sort and Fisher-Yates are fast enough.


Bias
Biases can have many forms. To help see how the bias look, I count up which position each element end up getting. Here's my code for that:
JavaScript:
function shuffleSyncBiasTest(start, times) {
  counts = [];
  for (let t = 0; t < times; t++) {
    array = start.clone();
    array.sort(() => Math.random() - 0.5);
    for (let i = 0; i < array.length; i++)
    {
      var element = array[i];
      if (counts[element] === undefined)
      {
        counts[element] = [];
      }
      var count = counts[element];
      if (count[i] === undefined)
      {
        count[i] = 1;
      }
      else
      {
        count[i]++;
      }
    }
  }
  return counts;
}

function shuffleFisherYates(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = Math.floor(Math.random() * (i + 1));
    const temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
}

function shuffleFisherYatesBiasTest(start, times) {
  counts = [];
  for (let t = 0; t < times; t++) {
    array = start.clone();
    shuffleFisherYates(array);
    for (let i = 0; i < array.length; i++)
    {
      var element = array[i];
      if (counts[element] === undefined)
      {
        counts[element] = [];
      }
      var count = counts[element];
      if (count[i] === undefined)
      {
        count[i] = 1;
      }
      else
      {
        count[i]++;
      }
    }
  }
  return counts;
}

I run each shuffle a million times again:
shuffleSyncBiasTest($array, 1000000);
shuffleFisherYatesBiasTest($array, 1000000);

Here is my results after I put them into Excel, divide by a million and use the percentage number format:
1722150914622.png

Spoiler: Raw Data
shuffleSyncBiasTest($array, 1000000);
[298158, 297318, 199273, 113738, 60488, 31025]
[298938, 298364, 197801, 113258, 60411, 31228]
[198086, 199203, 241004, 185371, 113682, 62654]
[113432, 113408, 185531, 259970, 202438, 125221]
[60077, 60649, 114085, 203092, 312653, 249444]
[31309, 31058, 62306, 124571, 250328, 500428]

shuffleFisherYatesBiasTest($array, 1000000);
[166651, 167229, 166820, 166311, 166322, 166667]
[167235, 166061, 166448, 166895, 166643, 166718]
[165670, 166609, 166984, 166782, 167467, 166488]
[166613, 166497, 166212, 167002, 166468, 167208]
[166677, 166598, 167500, 166240, 166595, 166390]
[167154, 167006, 166036, 166770, 166505, 166529]

This is a really interesting result. Fisher-Yates has this nice uniform distribution whereas the earlier numbes in the Sync shuffle has a tendency to be placed earlier in the resulting array. Both can make sense depending on how you want to design the randomness in your game.

Based on this information I would use Fisher-Yates as the standard option. I may use the Sync shuffle where I specifically want to skew the distribution in the illustrated way.
Neither of these options have that much control though. For more control I recommend searching for how to implement a weighted shuffle.

Note: Nothing here is truly random. Not that true randomness really matters that much in the vast majority of games.

Original thread: https://forums.rpgmakerweb.com/threads/randomizing-a-map-with-premade-rooms.170538/