So I have a problem in constructing randomly produced dialogue. I have 10 pairs of pieces of advice that contradict each other, and I want the user to have the opportunity to look through them all.

But here’s the thing: I don’t want the contradictory pieces of advice to appear next to each other too soon.

It’s possible to just random-shuffle the pieces of advice until no two opposite ones are adjacent or even 2 apart. That probably wouldn’t take too many iterations. It took on average 60, which would be acceptable, even with JavaScript, which can be slow.

But that got me thinking of ways I didn’t have to rely on the mercy of the RNG. And I came up with this, where the corresponding bits of advice are a1/b1, a2/b2, etc.

With n pairs of contradictory advice, sort (1, …, n) in random order. Let L1, L2, etc be the elements of the new list.

Then you could have a new list of (a(l1), a(l2), …, a(ln), b(l1), b(l2), … b(ln))

(Note–we can and probably should give 1/2 chance of flipping a(l3) and b(l3), etc.)

For instance in a simpler example 1,2,3,4,5 might go to 2,4,3,5,1 and then 2a,4b,3b,5a,1b,2b,4a,3a,5b,1a.

As I can assume people won’t play through my effort more than once (it would be for Neo Twiny Jam) they wouldn’t see this sleight of hand until it was too late. But I wanted to check if other people thought of a different solution so the distances are staggered more naturally and if any people had general thoughts on randomly or at least pseudo-randomly spacing events so certain pairs/groups don’t come too close.