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!
Combinations
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Combinations
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Macro Veteran
- Posts: 260
- Joined: Fri Apr 15, 2005 8:32 am
Re: Combinations
WOW!! That was impressive!
Thanks SO VERY much!!
Thanks SO VERY much!!