< Back to IRCAM Forum

Randomly Interlace Lists

I am stuck, trying to make a patch that will do:

Given 2 lists, for example:
(1 2 3 4)
(9 10 11)

it will interlace them randomly, each of the original 2 lists is in order, but interspersed with the other list, also in order:
(1 2 9 3 10 11 4)
(9 1 2 10 11 3 4)
(1 2 3 9 10 4 11)
etc…
are all correct solutions.

(In other words, I am asking for a random solution to a partially-ordered set, I believe).

I was trying to build a patch to do this with OMLOOP, but it involves multiple ListLoops. Maybe I can figure it out, but I’m sure someone else has done this before.

Anybody?

—Chris Bailey

Dear Chris,

Here is a solution for your problem,. Unfortunately it’s in lisp (put the file in the patcehs folder and launch om)
the function is ‘2listorderedshuffle’ .

Best
K

shuffle.lisp (693 Bytes)

I guess you could also try something with the OM ‘interlock’ function, too
…and use some random process to set the ‘list of indices’

Dear JEan,

I already thought of that. But unfortunately interlock doesn’t allow to interlock more than one item in a list, and with Chris examples this will not work :slight_smile:

K

Erratum, in my last comment on must read “But unfortunately interlock doesn’t allow to interlock more than one item in the same position of a list, …”

best
k

Thank you! that works.

Actually I had forgotten that “interlock” exists, but yes, you are correct it doesn’t quite work for what I wanted.

But this patch does, thanks.

–Chris Bailey