# tea bag flavors mixing algorithm [closed]

I bought three boxes of tea bags with different flavors (A, B, C).

I wish to mix them in such a way that - there is never two consecutive bags of the same flavor (ABCCAB is avoided) ; - the mixing is the "most" random, i.e. avoid patterns such as ABCABCABC... or ABABAB...BCBCBC...CACACA.

Is there a known algorithm for this mix?

Presently I randomly shuffle many "ABC" and concatenate the results, swapping the first letters if the latest letter of the previous shuffle is the same than the beginning of the new shuffle (...ABCCAB => ...ABCACB).

I guess I could improve this algorithm by pre-computing the permutations of ABC, and draw one permutation among the ones who do not begin with the same letter than the previous permutation.

I tried to "google" this problem but as a French native speaker, I probably miss the appropriate key-words.

• I'm not sure that this is the right site for your question, it doesn't seem to have much to do with Computational Science. Perhaps it would be better asked at stackoverflow.com. – High Performance Mark Nov 30 '18 at 10:32
• If this is homework, can you mark it as such? What is the underlying problem you are trying to solve? – Kirill Nov 30 '18 at 12:33
• As a teacher, I give homeworks, not do them :). The problem is exactly what I exposed : I have three boxes of tea bags and want to mix them to avoid having only one flavor at the end, if I draw them. Moreover, the algorithm, if it exit, could be used for producing a random list of "calls to the chalkboard" for my students, avoiding to call the same student two times consecutively. I guess there are other uses. – Dominique Nov 30 '18 at 14:11