Random position in array with buffers

Hi,
I’m currently trying to play some buffers using OSC from another app.
I have two arrays filled with paths to samples.

~cy = Array.new;
~folder = PathName.new("/home/samples/808cy");
~folder.entries; 
(
~folder.entries.do({
arg path;
~cy = ~cy.add(Buffer.read(s, path.fullPath));
});
)

If I play

~cy.at(9).play;

it works, the same with the other array.
Then I have the SynthDef for playing it:

(
SynthDef.new(\playbuf, {|amp=1, out=0, buf, da=2, rate =1|
var sig;
sig = PlayBuf.ar(1, buf, BufRateScale.kr(buf) * rate, doneAction:da);
sig = sig*amp;
Out.ar(out, sig);
}).add;
)

Synth.new(\playbuf, [\buf, ~feel[2].bufnum])

Works too.
I’m trying to play a random sample from one of those folders depending on the OSC input.
The part of the code that works with that is this one:

switch(msg[1],
		[1,3], {Synth.new(\playbuf, [\buf,  ~feel[0..5]])},
		[2], {Synth.new(\playbuf, [\buf, ~cy[0..21]])}

This clearly doesnt work.
I’ve also tried:

~feel.rand[0.4.rand2]]
~feel[0..5]]
~feel.choose

I think I’m now just coding without real understanding of what is happening, so I though it was better to ask.
Any tip appreciated :heart:

Switch syntax should be

switch(
    value, { ... },  // *no brackets* around value
    value, { ... },  // and, all single values, no multiple-matches
)

// or
switch(...)
    { value } { ... }
    { value } { ... };

And, ~feel.choose~feel[a..b] returns a sub-array, not a random choice.

hjh

Hi, thank you!
I’ve ended up doing something like this

		1, {Synth.new(\playbuf, [\buf, b[\feel][0..4].choose]) },
		2, {Synth.new(\playbuf, [\buf, b[\cy][0..5].choose])},

which kind of does what I wanted.
Thank you for the guidance!