mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Merge pull request #9659 from PsiOmegaDelta/150604-Shuffle
The shuffle proc can now handle both normal and associative lists.
This commit is contained in:
@@ -169,16 +169,15 @@ proc/listclearnulls(list/list)
|
||||
return output
|
||||
|
||||
//Randomize: Return the list in a random order
|
||||
/proc/shuffle(var/list/shufflelist)
|
||||
if(!shufflelist)
|
||||
/proc/shuffle(var/list/L)
|
||||
if(!L)
|
||||
return
|
||||
var/list/new_list = list()
|
||||
var/list/old_list = shufflelist.Copy()
|
||||
while(old_list.len)
|
||||
var/item = pick(old_list)
|
||||
new_list += item
|
||||
old_list -= item
|
||||
return new_list
|
||||
|
||||
L = L.Copy()
|
||||
|
||||
for(var/i=1; i<L.len; i++)
|
||||
L.Swap(i, rand(i,L.len))
|
||||
return L
|
||||
|
||||
//Return a list with no duplicate entries
|
||||
/proc/uniquelist(var/list/L)
|
||||
|
||||
Reference in New Issue
Block a user