MV Array - Coordinates X Y

I'm trying to distribute 10 x and y coordinates to 20 variables. I'm using random and splice so that i don't have to scramble the values inside the array. Then i need not worry since the last element is removed.
1635595825391.png


The array is for a 5 x 2. When i use splice, I end up with the same coordinate for example (248,445) x2.. so these 2 pictures i show overlaps instead, which is wrong.

JavaScript:
var xpos = [248, 316, 384, 452, 520, 248, 316, 384, 452, 520];
var ypos = [445, 445, 445, 445, 445, 503, 503, 503, 503, 503];
$gameVariables.setValue(22, xpos);
$gameVariables.setValue(23, ypos);

var arr = $gameVariables.value(22);
$gameVariables.setValue(41, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(42, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(43, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(44, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(45, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(46, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(47, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(48, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(49, arr.splice(Math.floor(Math.random() * arr.length), 1));
$gameVariables.setValue(50, arr.splice(Math.floor(Math.random() * arr.length), 1));

var arr2 = $gameVariables.value(23);
$gameVariables.setValue(51, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(52, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(53, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(54, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(55, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(56, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(57, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(58, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(59, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
$gameVariables.setValue(60, arr2.splice(Math.floor(Math.random() * arr2.length), 1));
The main problem is that you are splitting up the coordinates: for example, this allows (248, 445) and (316, 503) to rearrange themselves as (248, 503) and (316, 445).

Also, you are technically setting each of the variables 41~60 to length-1 arrays rather than numbers, because splice returns an array of values:
That's an easy mistake to make, especially because when it is displayed as a string (e.g. in the F9 menu) it looks like a normal number, no brackets or anything. 😴

Consider something like this instead:
JavaScript:
var arr = [
  {x:248, y:445}, {x:316, y:445}, {x:384, y:445}, {x:452, y:445}, {x:520, y:445},
  {x:248, y:503}, {x:316, y:503}, {x:384, y:503}, {x:452, y:503}, {x:520, y:503}
];
for (var n = 1; n <= 10; n++) {
  var pos = arr.splice(Math.randomInt(arr.length), 1)[0];
  $gameVariables.setValue(40 + n, pos.x);
  $gameVariables.setValue(50 + n, pos.y);
}
I.e. make each pair of coordinates an object, and select one of those objects each time. 😤
What are you actually looking for from this? It's unclear which part you're asking for help with.
thank you very much @caethyril !

@Trihan im asking how to distribute the x y coordinates to 20 variables correctly because i get duplicates.

Original thread: https://forums.rpgmakerweb.com/threads/array-coordinates-x-y.141671/