Combinations

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
fightcancer
Macro Veteran
Posts: 239
Joined: Fri Apr 15, 2005 8:32 am

Combinations

Post by fightcancer » Mon Mar 20, 2017 5:41 am

If I have X different items, how can I get MS to select a combo at random? The number of possible combos should be X! where X is the number of elements to choose from.

For example, If I have 3 items--A, B, C--and order doesn't matter, how can I get MS to generate a combo at random?

ABC
ACB
BAC
BCA
CAB
CBA

Thanks!

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Combinations

Post by Marcus Tettmar » Mon Mar 20, 2017 9:10 am

How about this:

Code: Select all

//Set up an array of items
Let>NumItems=3
ArrayDim>Chars,NumItems
Let>Chars_1=A
Let>Chars_2=B
Let>Chars_3=C

//loop to create random string of items
Let>theLen=0
Let>NewString={""}
While>theLen<NumItems
  Random>NumItems,RandID
  Let>RandID=RandID+1
  Let>ThisChar=Chars_%RandID%
  Pos>ThisChar,NewString,1,pGotAlready
  If>pGotAlready=0
    Let>NewString=%NewString%%ThisChar%
  Endif
  Length>NewString,theLen
EndWhile

//display result
MessageModal>NewString
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fightcancer
Macro Veteran
Posts: 239
Joined: Fri Apr 15, 2005 8:32 am

Re: Combinations

Post by fightcancer » Mon Mar 20, 2017 2:56 pm

WOW!! That was impressive!

Thanks SO VERY much!!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts