# Using the modes

**URL:** <https://in-thread.sonic-pi.net/t/using-the-modes/425>\
**Category:** Creations & Ideas\
**Created:** [November 16, 2017, 11:03pm UTC](https://in-thread.sonic-pi.net/t/using-the-modes/425 "2017-11-16T23:03:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raul](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/raul/32/265_2.png) [@Raul](https://in-thread.sonic-pi.net/u/Raul)\
**Post date:** [November 16, 2017, 11:03pm UTC](https://in-thread.sonic-pi.net/t/using-the-modes/425/1 "2017-11-16T23:03:50Z")

</div>

The idea is simple, a random number is generated, between 0 and 7, which corresponds to a position in several matrices (: c4,: major -: d4,: dorian -: e4,: phrygian) creating with a single number one melodic sequence 1 2 3 2, on the C major scale in this case …

I apologize for my limited knowledge of English

```ruby
live_loop :tempo do
  use_synth :tb303
  play :c2,cutoff: 80,release: 1.8,amp: 0.5
  sleep 2
end

with_fx :reverb, mix: 0.5, amp: 0.75 do
  live_loop :mel do
    use_synth :dsaw
    nota= rand_i(0..7)
    dur= rrand(0.45,0.50)
    play scale(:c4,:major)[nota],release: dur
    sleep dur
    play scale(:d4,:dorian)[nota],release: dur/2
    sleep dur/2
    play scale(:e4,:phrygian)[nota],release: dur/2
    sleep dur/2
    sleep 1-(dur*2)
    use_synth :square
    play scale(:d4,:dorian)[nota],release: dur
    sleep 1
  end
end

```

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [November 17, 2017, 8:01am UTC](https://in-thread.sonic-pi.net/t/using-the-modes/425/2 "2017-11-17T08:01:43Z")

</div>

This sounds great Raul.  
I think there is one slight error. The syntax for the line  
`nota=rand_i(0...7`)  
is not quite right. It should either be  
`nota=rand_i(8) #this give random integer in range 0..7`  
(note the last integer here is NOT part of the returned range of values)  
or  
`nota = rrand_i(0,7) #this gives random integer in range 0..7`

You can see the syntax if you look up `rand_i` and `rrand_i` in the lang section of the Help file.  
I like the idea of mixing up notes from different scales. very nice.

---

<div class="post-metadata">

**Author:** ![Raul](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/raul/32/265_2.png) [@Raul](https://in-thread.sonic-pi.net/u/Raul)\
**Post date:** [November 17, 2017, 2:42pm UTC](https://in-thread.sonic-pi.net/t/using-the-modes/425/3 "2017-11-17T14:42:49Z")

</div>

Thanks Robin, you can use the same system to harmonize, or repeat four-bar melodies as in this example

```ruby
with_fx :reverb, mix: 0.5, amp: 0.75 do
  live_loop :mel do
    use_synth :dsaw
    use_random_seed 2017
    4.times do
      nota= rand_i(8)
      dur=0.5
      play scale(:a3,:aeolian)[nota],release: dur
      sleep dur
      play scale(:c4,:major)[nota],release: dur/2
      play scale(:e4,:phrygian)[nota],release: dur/2
      sleep dur
      play scale(:c4,:major)[nota],release: dur/2
      sleep dur/2
      play scale(:d4,:dorian)[nota],release: dur
      sleep dur
      play scale(:b3,:locrian)[nota],release: dur/2
      sleep dur/2
    end
  end
end

```

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [November 17, 2017, 5:13pm UTC](https://in-thread.sonic-pi.net/t/using-the-modes/425/4 "2017-11-17T17:13:54Z")

</div>

This is nice. I’m going to have a play with it.
