mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-12 03:02:54 +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
|
return output
|
||||||
|
|
||||||
//Randomize: Return the list in a random order
|
//Randomize: Return the list in a random order
|
||||||
/proc/shuffle(var/list/shufflelist)
|
/proc/shuffle(var/list/L)
|
||||||
if(!shufflelist)
|
if(!L)
|
||||||
return
|
return
|
||||||
var/list/new_list = list()
|
|
||||||
var/list/old_list = shufflelist.Copy()
|
L = L.Copy()
|
||||||
while(old_list.len)
|
|
||||||
var/item = pick(old_list)
|
for(var/i=1; i<L.len; i++)
|
||||||
new_list += item
|
L.Swap(i, rand(i,L.len))
|
||||||
old_list -= item
|
return L
|
||||||
return new_list
|
|
||||||
|
|
||||||
//Return a list with no duplicate entries
|
//Return a list with no duplicate entries
|
||||||
/proc/uniquelist(var/list/L)
|
/proc/uniquelist(var/list/L)
|
||||||
|
|||||||
Reference in New Issue
Block a user