# Searching for ideas for random rhythm

**URL:** <https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633>\
**Category:** Creations & Ideas\
**Created:** [January 22, 2018, 10:34am UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633 "2018-01-22T10:34:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarieRose](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/marierose/32/411_2.png) [@MarieRose](https://in-thread.sonic-pi.net/u/MarieRose)\
**Post date:** [January 22, 2018, 10:34am UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/1 "2018-01-22T10:34:12Z")

</div>

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

👌

---

<div class="post-metadata">

**Author:** ![mrbombmusic](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mrbombmusic/32/2282_2.png) [@mrbombmusic](https://in-thread.sonic-pi.net/u/mrbombmusic)\
**Post date:** [January 22, 2018, 4:35pm UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/2 "2018-01-22T16:35:51Z")

</div>

Here would be somewhere to start

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

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

```

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](http://in-thread.sonic-pi.net/t/more-real-randomization/608/5)

Hope that helps

---

<div class="post-metadata">

**Author:** ![MarieRose](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/marierose/32/411_2.png) [@MarieRose](https://in-thread.sonic-pi.net/u/MarieRose)\
**Post date:** [January 23, 2018, 11:13am UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/3 "2018-01-23T11:13:27Z")

</div>

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  
with  
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 🤪

---

<div class="post-metadata">

**Author:** ![Eli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/eli/32/116_2.png) [@Eli](https://in-thread.sonic-pi.net/u/Eli)\
**Post date:** [January 23, 2018, 11:42am UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/4 "2018-01-23T11:42:13Z")

</div>

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.

Eli…

```ruby
use_bpm 60
set_volume! 5
use_random_seed 999

live_loop :bar do
  sleep 1
end

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
  tick
end
```

---

<div class="post-metadata">

**Author:** ![MarieRose](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/marierose/32/411_2.png) [@MarieRose](https://in-thread.sonic-pi.net/u/MarieRose)\
**Post date:** [January 23, 2018, 12:56pm UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/5 "2018-01-23T12:56:16Z")

</div>

ooooooooooook!!! than u so much!!!  
this is a good start 👌  
🕶  
but…  
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

---

<div class="post-metadata">

**Author:** ![Eli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/eli/32/116_2.png) [@Eli](https://in-thread.sonic-pi.net/u/Eli)\
**Post date:** [January 23, 2018, 9:58pm UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/6 "2018-01-23T21:58:06Z")

</div>

> [@MarieRose](#):
>
> can i do the same with the internal rhythm/instruments of sonic pi?

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

> [@MarieRose](#):
>
> ps. i can’t use loop inside sonic pi by now…how can u attached these loops in a simple code?

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).

Eli…

---

<div class="post-metadata">

**Author:** ![MarieRose](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/marierose/32/411_2.png) [@MarieRose](https://in-thread.sonic-pi.net/u/MarieRose)\
**Post date:** [January 31, 2018, 5:33pm UTC](https://in-thread.sonic-pi.net/t/searching-for-ideas-for-random-rhythm/633/7 "2018-01-31T17:33:48Z")

</div>

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

thank u so much  
🤗
