Skip to content

Instantly share code, notes, and snippets.

@JokerMartini
Last active July 5, 2017 14:20
Show Gist options
  • Save JokerMartini/a2452be53a6dfc780688 to your computer and use it in GitHub Desktop.
Save JokerMartini/a2452be53a6dfc780688 to your computer and use it in GitHub Desktop.
Maxscript: Randomize Array returns an array of shuffled items
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