Notifications
Clear all

[Closed] Random Array

 mef

I was wondering if there was an easy way to shuffle the contents of an array.
Currently I have a script that stores objects in the order that they where picked but I want to be able to alter this so that it is random.

Marc

2 Replies

Try this:

oldArr = #() -- make this your original array
 newArr = #()
 while oldArr.count > 0 do (
      rndItem = random 1 oldArr.count -- randomly choose index from array
      append newArr oldArr[rndItem] -- selected item to new array
      deleteItem oldArr rndItem -- delete item from oldArr so it doesn't duplicate
 )

Make sure to set oldArr to your original array.

-Eric

 mef

Thanks Eric. I’ll give it a try this weekend.

Marc