Needahand 1 Posted November 20, 2015 Report Share Posted November 20, 2015 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: ChigagoLondonRomeParisWashingtonSeattle I want to shuffle the list it reads differently every time, so: SeattleChigagoLondonParisRomeWashington WashingtonSeattleParisLondonRomeChigago 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!!!! Quote Link to post Share on other sites
pash 504 Posted November 20, 2015 Report Share Posted November 20, 2015 not sure otherI'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/ Quote Link to post Share on other sites
deliter 203 Posted November 20, 2015 Report Share Posted November 20, 2015 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) Quote Link to post Share on other sites
Needahand 1 Posted November 20, 2015 Author Report Share Posted November 20, 2015 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. Quote Link to post Share on other sites
Needahand 1 Posted November 20, 2015 Author Report Share Posted November 20, 2015 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,SeattleWashington,Chigago,Seattle,London,Rome,ParisLondon,Washington,Chigago,Paris,Seattle,RomeLondon,Chigago,Paris,Washington,Seattle,Romeetcetcetc Quote Link to post Share on other sites
tnhomestead 16 Posted November 21, 2015 Report Share Posted November 21, 2015 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! Quote Link to post Share on other sites
RickBot0906 10 Posted December 2, 2015 Report Share Posted December 2, 2015 Just a suggestion, why don't you assign a number to that list For example London = 1Chicago = 2Paris = 3Washington = 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. 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.