Jump to content
UBot Underground

Recommended Posts

Hi all,

 

Can anyone help with this, I have scoured the forum and found related posts but nothing actually works properly.

 

It seems like a simple task - I want to shuffle a list multiple times (maybe thousands of times).

 

Say I have a list of 6 items:

 

Chigago

London

Rome

Paris

Washington

Seattle

 

I want to shuffle the list it reads differently every time, so:

 

Seattle
Chigago
London
Paris
Rome
Washington

 

Washington
Seattle
Paris
London
Rome
Chigago

 

etc, etc so with 6 items there will be 720 permutations so I want to loop it 720 times and get 720 different lists.

 

I have tried various methods using random list item, remove list item, list position etc but can't seem to get it to work. I realize that I have to select a random list item, add it to a list, then remove it from the list. But everything I try seems to fail, mostly because it returns the list position (which is a number) not the text which is in that list position.

 

Hope I've explained it properly, can anyone help PLEASE!!!!

Link to post
Share on other sites

not sure other

I'm use plugin only

add list to list(%myList1,$list from text("Chigago
London
Rome
Paris
Washington
Seattle",$new line),"Delete","Global")
alert($plugin function("Advanced Data Text File.dll", "$shuffle list", %myList1))

http://network.ubotstudio.com/forum/index.php?/topic/17168-sell-plugin-advanced-data-text-file/

Link to post
Share on other sites

Certainly not an easy task ha ha
 
I had to google the answer,that kind of maths would be way too complex for me,run this code,and in your debugger,will be a table called myTable,with all possible combinations,you can put other lists too into this,since it is a command

 

It takes the debugger a few seconds to load the table in the debugger,so click refresh after a few seconds(also unclick auto refresh on debugger)

 

this script can only handle 8 items max,anymore than that the javascript&the web page you are on will crash,which is 40320 combinations

 

You can then grab lists from the table using "list from table column" function

 

I would suggest using Kevs Large Tables plugin for this operation,even trying to view a table that big in the debugger will crash Ubot

add list to list(%towns,$list from text("Chigago
London
Rome
Paris
Washington
Seattle",$new line),"Delete","Global")
define allCombo(#list) {
    add list to list(%myList,$list from text(#list,$new line),"Delete","Local")
    clear table(&myTable)
    set(#position,0,"Local")
    set(#JSArray,"","Local")
    loop($list total(%myList)) {
        set(#JSArray,"{#JSArray}\"{$list item(%myList,#position)}\",","Local")
        increment(#position)
    }
    set(#JSArray,"[{$replace regular expression(#JSArray,",$","")}]","Local")
    run javascript("var permArr = [],
  usedChars = [];

function permute(input) \{
  var i, ch;
  for (i = 0; i < input.length; i++) \{
    ch = input.splice(i, 1)[0];
    usedChars.push(ch);
    if (input.length == 0) \{
      permArr.push(usedChars.slice());
    \}
    permute(input);
    input.splice(i, 0, ch);
    usedChars.pop();
  \}
  return permArr
\};
")
    add list to list(%results,$find regular expression($replace regular expression($eval("JSON.stringify(permute({#JSArray}))"),"^\\[|\\]$",""),"\\[.+?\\]"),"Delete","Local")
    set(#position,0,"Local")
    loop($list total(%results)) {
        clear list(%resultseach)
        add list to list(%resultseach,$list from text($replace regular expression($list item(%results,#position),"\"|\\[|\\]",""),","),"Delete","Local")
        add list to table as column(&myTable,0,$table total columns(&myTable),%resultseach)
        increment(#position)
    }
}
allCombo(%towns)

Link to post
Share on other sites

 

Certainly not an easy task ha ha

 

I had to google the answer,that kind of maths would be way too complex for me,run this code,and in your debugger,will be a table called myTable,with all possible combinations,you can put other lists too into this,since it is a command

 

It takes the debugger a few seconds to load the table in the debugger,so click refresh after a few seconds(also unclick auto refresh on debugger)

 

this script can only handle 8 items max,anymore than that the javascript&the web page you are on will crash,which is 40320 combinations

 

You can then grab lists from the table using "list from table column" function

 

I would suggest using Kevs Large Tables plugin for this operation,even trying to view a table that big in the debugger will crash Ubot

add list to list(%towns,$list from text("Chigago
London
Rome
Paris
Washington
Seattle",$new line),"Delete","Global")
define allCombo(#list) {
    add list to list(%myList,$list from text(#list,$new line),"Delete","Local")
    clear table(&myTable)
    set(#position,0,"Local")
    set(#JSArray,"","Local")
    loop($list total(%myList)) {
        set(#JSArray,"{#JSArray}\"{$list item(%myList,#position)}\",","Local")
        increment(#position)
    }
    set(#JSArray,"[{$replace regular expression(#JSArray,",$","")}]","Local")
    run javascript("var permArr = [],
  usedChars = [];

function permute(input) \{
  var i, ch;
  for (i = 0; i < input.length; i++) \{
    ch = input.splice(i, 1)[0];
    usedChars.push(ch);
    if (input.length == 0) \{
      permArr.push(usedChars.slice());
    \}
    permute(input);
    input.splice(i, 0, ch);
    usedChars.pop();
  \}
  return permArr
\};
")
    add list to list(%results,$find regular expression($replace regular expression($eval("JSON.stringify(permute({#JSArray}))"),"^\\[|\\]$",""),"\\[.+?\\]"),"Delete","Local")
    set(#position,0,"Local")
    loop($list total(%results)) {
        clear list(%resultseach)
        add list to list(%resultseach,$list from text($replace regular expression($list item(%results,#position),"\"|\\[|\\]",""),","),"Delete","Local")
        add list to table as column(&myTable,0,$table total columns(&myTable),%resultseach)
        increment(#position)
    }
}
allCombo(%towns)

Thanks Deliter, I think I possibly didn't explain myself properly. I realise that these lists could be huge. I didn't want it to do every possible combination but a set number which I would put in the loop. For instance if there was 8 items in the list I could do a loop of 1000 and it would give me 1000 different lists containing those 8 items, I only used the 6 item list as it was manageable and had a reasonable number of results. My lists could have 20 or 30 items. It is really the method of selecting a random list item, adding it to a list then deleting it, till all list items are used, then repeating the process.

Link to post
Share on other sites

I should also really add that I eventually need the output to be a comma separated list as one list item so I would eventually end up with one list containing:

 

Chigago,London,Rome,Paris,Washington,Seattle

Washington,Chigago,Seattle,London,Rome,Paris

London,Washington,Chigago,Paris,Seattle,Rome

London,Chigago,Paris,Washington,Seattle,Rome

etc

etc

etc

Link to post
Share on other sites

Okay, maybe use 3 lists -- one with data, another to track the data. IE list 1 is Chicago, New York, Memphis and list 2 is your used list and list 3 is your random list. Get a random list item from list 1, add to list 3 and save the item location to the used list(list 2). On the second  random to the last one, do a random number, check to see if its been used or not from list 2. If it has not been used save the item to the list 3 and save the item location to the used number list(list 2), if the item was used already, then get a new random number. This would allow you to build your csv pretty easily, leave your original list of thousands intact for future use and when you need a new list built, just delete the entries in the used list and start over.

 

Hope that made sense and helps!

Link to post
Share on other sites
  • 2 weeks later...

Just a suggestion, why don't you assign a number to that list

 

For example

 

London = 1

Chicago = 2

Paris = 3

Washington = 4 so on and so on

 

Now within your loop you pick a random number between 1-6 and for all the cities. 

 

You end up with (1,3,5,7,2,6)

 

Then (2,4,1,6,5,7) so on and so on, lastly you convert the numbers back to cities.

 

If variable = 3 then print Paris. 

 

I realize you may run into duplicates, but it is better than nothing at all. 

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...