Jump to content
UBot Underground

Helpful?  

3 members have voted

  1. 1. What do you think?

    • Yes :)
    • No :(
      0
    • Whatever :|
      0


Recommended Posts

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

  • Like 3
Link to post
Share on other sites
  • 2 weeks later...
  • 7 months later...

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

Link to post
Share on other sites

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 %thelist
We'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 by dankass
  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...