Ticking through samples randomly from outside folder


Does anyone have a an example of how to tick through a folder of samples at random?

I would like to point sonic pi to a directory and let it tick or choose samples,


Hi there,

tick is never random, it’s just a basic counter: 0, 1, 2, 3, 4....

For example:

live_loop :foo do
    sample path_to_sample_folder, tick
    sleep 8

This will play each successive sample (alphabetically in order) with 8 beats between sample triggers. It will always play them alphabetically as tick will always increase by one every time it is called (assuming there’s only one call to tick in the current live loop).

However, if you want it to pick a random sample, you need to use pick:

live_loop :foo do
    sample path_to_sample_folder, pick
    sleep 8

The caveat here is that in Sonic Pi, there’s no real randomness, so that the same code always produces the same sounds. You can manipulate this though by using random seeds. For more information about randomness please see: http://sonic-pi.net/tutorial.html#section-4

I hope that this helps :slight_smile:


dirsample =" sample path_to_sample_folder"

live_loop :foo do
q = rrand_i(1000)
sample dirsample, q
sleep sample_duration dirsample,q