Last active
July 5, 2017 14:20
-
-
Save JokerMartini/a2452be53a6dfc780688 to your computer and use it in GitHub Desktop.
Maxscript: Randomize Array returns an array of shuffled items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
oldarray=#("One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten") | |
fn RandomizeArray arr:#() = | |
( | |
local list = #() | |
while arr.count != 0 do | |
( | |
id = random 1 arr.count | |
append list arr[id] | |
deleteItem arr id | |
) | |
list | |
) | |
fn shuffle &arr = | |
( | |
local temp, swapIndex, counter = arr.count + 1 | |
while counter > 1 do | |
( | |
swapIndex = random 1 (counter -= 1) | |
temp = arr[counter] | |
arr[counter] = arr[swapIndex] | |
arr[swapIndex] = temp | |
) | |
) | |
fn shuffle arr = | |
( | |
for counter = arr.count to 1 by -1 collect | |
( | |
local swapIndex = random 1 counter | |
swap arr[swapIndex] arr[counter] | |
) | |
) | |
fn shuffle arr = | |
( | |
for counter = arr.count to 1 by -1 collect (swap arr[random 1 counter] arr[counter]) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment