Randomly pair up items from 2 arrays?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi All. I have 2 arrays each with the same number of items. One array stores my npc’s and the other stores positions on the map.

I want to randomly pair up each npc with a position on the map.

How do I do that?

:bust_in_silhouette: Reply From: Magso

A for loop can do this.

for thisnpc in positions.size():
    npcs[thisnpc].position = positions[thisnpc]

If you want it to be random you can shuffle one of the arrays.

P.S for 3D change npcs[thisnpc].position to npcs[thisnpc].translation