View Full Version : Random Array
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
|
|
PiXeL_MoNKeY
12-07-2007, 08:02 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
Thanks Eric. I'll give it a try this weekend.
Marc
CGTalk Moderation
12-07-2007, 09:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.