Notifications
Clear all
[Closed] Random Array
Dec 07, 2007 8:10 pm
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
Dec 07, 2007 8:10 pm
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