Syntax: Shuffle(var/List)
Code:
proc
Shuffle(list/shuffle)
for(var/i in 1 to shuffle.len) shuffle.Swap(i,rand(1,shuffle.len-1))
return shuffle
Example:
mob/verb
ShuffleList()
var/list/deck = list()
for(var/cardNumber in 1 to 52) deck += cardNumber
deck = Shuffle(deck)
for(var/card in deck) world << card
Incorrect. Unlike your shuffle procedure that randomly picks elements to be removed and readded(In some cases leaving results like 1 and 2 unshuffled; thus proving yours is actually the inefficient procedure. As well as this benchmarking better.) this shuffle procedure loops through the entire length of the array starting at the first element all the way to the last. The only way an element would end up in the same position would be if it's shuffled out of it, then back into it. I'd appreciate if you decided to actually read the code before jumping to split second decisions. Thank you.