Praney Behl 314 Posted August 5, 2012 Report Share Posted August 5, 2012 Guys been a while I shared some little code snippet. So here is a custum built shuffle list function that takes a list as input and return the shuffled list back to a variable or a list. [sHUFFLE LIST] Function: define $shuffle list(#your_list_goes_here) { clear list(%list_to_shuffle) clear list(%list_shuffled) add list to list(%list_to_shuffle, $list from text(#your_list_goes_here, $new line), "Delete", "Global") set(#list_total, $list total(%list_to_shuffle), "Global") set(#temp, $list total(%list_to_shuffle), "Global") loop(#list_total) { set(#random_list_item, $rand(0, #temp), "Global") add item to list(%list_shuffled, $list item(%list_to_shuffle, #random_list_item), "Delete", "Global") remove from list(%list_to_shuffle, #random_list_item) decrement(#temp) } return(%list_shuffled) } Hope it helps Praney 3 Quote Link to post Share on other sites
warriorfullights 0 Posted August 15, 2012 Report Share Posted August 15, 2012 Great share! Thanks! Quote Link to post Share on other sites
dankass 52 Posted March 23, 2013 Report Share Posted March 23, 2013 For some reason I keep ending up with an error saying I have exceeded the range of the list. I look in debugger and there is 1 blank entry randomly in the middle of the new %list_shuffled list, and then there is a remainder entry (the last one missing from the list) in the variable %list_to_shuffle. I have ensured there is no blank line in my list anywhere. Has anything changed that may make this not work quite right? Thanks Quote Link to post Share on other sites
dankass 52 Posted March 24, 2013 Report Share Posted March 24, 2013 (edited) I spent half the day trying to find an 'easy' way to do this, and finally figured something out as soon as I noticed the ubot 4.2.15 update which opened an idea of an easy new way to do this for me... So.... Just in case someone in the future wants to do a "Shuffle" I was able to accomplish a "Shuffle" using the new "sort table" (4.2.15+) command like this: lets say list name is %thelistWe'll output a new list as %sortedlist clear list(%randnumlist) clear list(%sortedlist) clear table(&thelist) loop($list total(%thelist)) { add item to list(%randnumlist, $rand(0, 9999), "Delete", "Global") } add list to table as column(&thelist, 0, 0, %thelist) add list to table as column(&thelist, 0, 1, %randnumlist) plugin command("TableCommands.dll", "sort table", &thelist, 1) add list to list(%sortedlist, $plugin function("TableCommands.dll", "$list from table", &thelist, "Column", 0), "Delete", "Global") I personally just used the table itself (cuz thats what I was trying to do anyway) and skipped converting it back to a new list but wanted to show that step anyway just in case using a LIST was important to someone. Edited March 24, 2013 by dankass 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.