Searching for ideas for random rhythm

hi there!!!
i am a newbie of sonic pi and i am used it to make music and to study composition at conservatory.
at the moment all is clear (thanks to u and to the developers) but i am trying to do new stuff with this language.
one of these new things is to insert random in a regular rhythm.
i would like to build up rhythms that, after a regular start, can be take unexpected ways.
how can i do???

thanks a lot


Here would be somewhere to start

16.times do
  play scale(:c4, :major).choose
  sleep 0.5

16.times do
  play scale(:c4, :major).choose
  sleep rrand(0.1, 1)

The second block will choose random sleep values between 0.1 and 1. However, be aware that it is not true randomness. Every time you play it , it will give you the same pattern. you can change the pattern by adding use_random_seed above the second block along with a number to change the pattern but it will still play the same way each time you run it.

Check out this thread for more about using true randomness as it seems applicable to what you might be trying to do -> More real randomization

Hope that helps

1 Like

thank u mr!!!
i tried your suggestion and it is right but does it right with the rhythm too?
i mean:
if i change
play scale(:c4, :major).choose
sample :drum_cymbal_pedal, sustain: 14, release: 8, amp: 2
sleep 0.25
does it work the same?
cause i tried this and sonic pi says to me “error”

cause i need random rhythm and not melody

anyway thanks a lot for the clear explanation about randomization

thanks :crazy_face:

Random rhythm?

The more samples you put in this line,

this_sample = [:loop_compus, :loop_safari].choose

the more mixed up your rhythm will be.


use_bpm 60
set_volume! 5
use_random_seed 999

live_loop :bar do
  sleep 1

live_loop :drums do
  sync :bar
  #  sample :loop_mika
  this_sample = [:loop_tabla, :loop_mika, :loop_compus, :loop_safari].choose
  start = [ 0.0 , 0.125 , 0.25 , 0.375 , 0.5 , 0.625 , 0.75 , 0.875 ].ring
  sample this_sample , beat_stretch: 4, start: start.look, rate: 0.5

ooooooooooook!!! than u so much!!!
this is a good start :ok_hand:
can i do the same with the internal rhythm/instruments of sonic pi?

sorry for my persistence but i am studying about this and i would like to prepare some studies exploiting all the sonic pi’s possibilities

but thank u so much

really thanks

ps. i can’t use loop inside sonic pi by now…how can u attached these loops in a simple code?


thanks again

Yes. Look at the example ‘[Illusionist] Ocean’ in the built-in examples
(in Sonic Pi click on ‘Examples’ in the bottom left corner).

I think you are talking about using your own ‘external’ samples now, if you read section
3.6 External Samples’ in the Tutorial, that should explain how.
(in Sonic Pi click on ‘Tutorial’ in the bottom left corner).


1 Like

thank u so much eli
and sorry for the delay in the answer
i have clear now the argument

thank u so much