Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Sat Jun 12, 2010 12:22 pm   

[3.19+] Suggestion: Random sorting
 
When you put in custom sorting options, would it be possible to get some sort of random sort option?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Jun 12, 2010 2:40 pm   
 
Code:
#LOCAL $RSort $NItem
#LOOP %numitems(@variable) {$NItem=%item(@variable, %random(1,%numitems(@variable));#ADDITEM $RSort $NItem;#DELITEM variable $NItem}
variable=$RSort


That should be a workable workaround if this never gets implemented. :P

Charneus
Reply with quote
ralgith
Sorcerer


Joined: 13 Jan 2006
Posts: 715

PostPosted: Sat Jun 12, 2010 10:20 pm   
 
I did this a much different way in zMUD... ;)
Code:
#WHILE (%numitems(@UnSorted) > 0) {
  #VAR rand %random(1, %numitems(@UnSorted))
  #VAR Sorted %additem(%item(@UnSorted, @rand), @SortedList)
  #VAR UnSorted %delnitem(@UnSorted, @rand)
}
_________________
CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Jun 14, 2010 4:51 pm   
 
Random sorting is tricky even using the new Json table custom sorting method. With the internal custom sorting, you create your own Compare routine that takes two string values and returns -1 if stringAstringB. This needs to be a consistent function that always returns the same value for a given pair of strings. A Random sort won't work with this kind of custom sorting architecture.

So, using the above suggestions to resort your list randomly when you want it will be what you need to use.

However, I need to ask why you need the actual list itself randomly sorted. Can't you just use the %random function to generate a random index value whenever you need to access something in your list?
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net