Select random selection of multiple items from list/ring?

New to Sonic-pi.
Been coding in Python for a while.

If we have a list (or ring) of values, is there a builtin that allows us to select multiple items from that at “random” .

(In Python I’d use random.sample(list, k) where k is the # of unique elements to be returned)

1 Like

@contumely - for a selection of functions you can chain onto the end of a ring to produce new rings, see the following:


thanks so much.
This is a lot of fun.

live_loop :oposopo do
  use_synth :sine
  q = (scale :d3, :pelog, num_octaves: 2).shuffle.take(5)
  play_pattern_timed q, [3.7, 0.8, 0.2], sustain: 6, decay: 3, release: 1.9
  sleep 5

Bro… when you really start diggin in? You can do some wicked, wicked things. Trust me. :slight_smile:

Welcome to the forums.


1 Like
for i in 0..k
1 Like

So if I learn a bit of Ruby I can use that in Sonic-pi?
Is the Sonic-pi language a superset of Ruby or is it a subset with specific extensions?
Or … ?

Closer to the latter. Sonic Pi is a DSL (Domain Specific Language) implemented with Ruby. While this means that there is some crossover, Sonic Pi is not Ruby - and total compatibility is not guaranteed or intended.

It’s quite possible to use some plain Ruby syntax currently, but such use is not officially supported and may or may not work in the future as Sonic Pi evolves. (There is always the possibility that some day the Sonic Pi DSL may be reimplemented in another base language entirely for example).

1 Like