# The subtile difference between "range" and "line"

**URL:** <https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095>\
**Category:** Support, Help & Resources\
**Created:** [August 2, 2024, 12:48pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095 "2024-08-02T12:48:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/3133_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)\
**Post date:** [August 2, 2024, 12:48pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095/1 "2024-08-02T12:48:28Z")

</div>

Hi there! @Hussein in two of his great videos speaks about “line” then “range”. In fact if you compare these two blocks, it’s the same thing, the same result:

```ruby
myrange = (range 0, 1, step: 0.1, inclusive: true)

10.times do
  play 60, release: 0.2, amp: myrange.tick
  sleep 0.25
end

myline = (line 0, 1, steps: 10, inclusive: true)

10.times do
  play 60, release: 0.2, amp: myline.tick
  sleep 0.25
end

```

I’d like just like to know if you see code contexts where “range” and “line” could bring something different…or perhaps not since, just the word “step/steps” seems to make the only difference.  
Thanks for attention

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [August 2, 2024, 1:36pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095/2 "2024-08-02T13:36:48Z")

</div>

Hi  
as per the docs, both line and range create a ring, with start and end values, with the subtle difference that range asks you to specify (and therefore have ‘greater control’ over), the size of the step; line also has a start and end value, but the step size is calculated based on the number of divisions within that range.

Speaking strictly as a non-coder/mathematician, the difference can _sometimes_ yield unexpected results, particularly when using either function for control of, for example, pitch.

```ruby
myrange = (range 0, 1, step: 0.2, inclusive: true)

5.times do
  tick
  val = myrange.look
  puts val
  play (val * 10) + 60, release: 0.2
  sleep 0.5
end

sleep 2
myline = (line 0, 1, steps: 5, inclusive: true)

5.times do
  tick
  val = myline.look
  puts val
  play (val * 10) + 60, release: 0.2
  sleep 0.5
end

```

At least, that’s how I think of the difference between the two, and therefore prefer to use range 😉

PD-Pi

---

<div class="post-metadata">

**Author:** ![beryann](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/beryann/32/3133_2.png) [@beryann](https://in-thread.sonic-pi.net/u/beryann)\
**Post date:** [August 2, 2024, 1:46pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095/3 "2024-08-02T13:46:40Z")

</div>

ok Brendan @brendanmac thanks for your interesting point of view…  
In the help doc, Sam @samaaron writes that “line is similar to range” but without giving details so, in certain context it seems interesting to use and compare the two possibilities 😀

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [August 2, 2024, 1:51pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095/4 "2024-08-02T13:51:05Z")

</div>

Hi  
others may disagree, or have different approaches but, generally, I tend to use range for larger steps - pitch, cutoff etc - and line for finer resolution control of normalised values, say, amplitude.

PD-Pi

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [August 2, 2024, 2:10pm UTC](https://in-thread.sonic-pi.net/t/the-subtile-difference-between-range-and-line/9095/5 "2024-08-02T14:10:43Z")

</div>

Subtle difference indeed; but note that Sam uses the phrase “similar to” and not “the same as”:

```ruby
ln1 = (range 0, 1, step: 0.1, inclusive: true)

ln2 = (line 0, 1, steps: 11, inclusive: true)

live_loop :stepsize do
  puts ln1.tick
  sleep 1
end

live_loop :divisions, delay: 0.1 do
  puts ln2.tick
  sleep 1
end

```

PD-Pi
