ID:195135
 
//Title: Simple In-Place List Shuffle
//Credit to: Jtgibson
//Contributed by: Jtgibson


//This takes a list of values and randomly shuffles them.
// This is an in-place random sort. It works well enough.

proc/shuffle(list/shuffle)
for(var/i = 1, i <= shuffle.len, i++)
var/pos = rand(1,shuffle.len)
var/temp = shuffle[pos]
shuffle[pos] = shuffle[i]
shuffle[i] = temp
return shuffle


///*
//Testing code/sample implementation
mob/verb/test_shuffle(T as message)
var/list/L = shuffle(dd_text2list(T, "\n"))

for(var/X in L) usr << X
//*/