# Randomisation (rand, rrand, choose)

**URL:** <https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100>\
**Category:** Support, Help & Resources\
**Created:** [June 21, 2020, 7:24pm UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100 "2020-06-21T19:24:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taxicletter](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@Taxicletter](https://in-thread.sonic-pi.net/u/Taxicletter)\
**Post date:** [June 21, 2020, 7:24pm UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100/1 "2020-06-21T19:24:53Z")

</div>

Hi,  
I understand “rrand”’ uses a not-really-random list and you can change that list with “seed”.  
From the tutorial, I’m not certain if “rand” is truly random or not? Same with “choose”: does it choose really random, or also pseudo-random?

---

<div class="post-metadata">

**Author:** ![hitsware](https://avatars.discourse-cdn.com/v4/letter/h/a9adbd/32.png) [@hitsware](https://in-thread.sonic-pi.net/u/hitsware)\
**Post date:** [June 21, 2020, 7:38pm UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100/2 "2020-06-21T19:38:15Z")

</div>

All computer generated " randomness " is pseudo …  
That usually suffices for music ( since it’s not like  
gambling , where one might cheat if they learn  
the patterns ) … : )

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [June 21, 2020, 8:11pm UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100/3 "2020-06-21T20:11:14Z")

</div>

As far as I know, SP uses the same list of random values for all functions involving randomization. If you need ‘real’ randomness, you can use an expression like:

```ruby
t = Time.now.to_i
use_random_seed t
puts rand

```

But actually a list of random values as the base of a randomization is very valuable, because it makes randomness repeatable (which seems to be contradictory): The assumption behind this concept is, that in a musical context you might indeed want to have some sort of randomness but once you share the code it should be the same choices as in the moment you created this randomness in the first place.

So, as far as I understand and appreciate, randomness in Sonic Pi means: Let it choose the first time and make this choice repeatable in order 1. to share and 2. to use it [as creative tool](https://in-thread.sonic-pi.net/t/random-pattern-generation/4098).

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [June 21, 2020, 8:43pm UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100/4 "2020-06-21T20:43:08Z")

</div>

> [@Taxicletter](#):
>
> I understand “rrand”’ uses a not-really-random list and you can change that list with “seed”.  
> From the tutorial, I’m not certain if “rand” is truly random or not? Same with “choose”: does it choose really random, or also pseudo-random?

Sonic Pi’s randomisation system is not random - it’s deterministic. This means that the same code will always produce the same sounds. This makes it possible to save your code, re-open it another time and know what it will do. You can also share code via email with a friend and know what they will hear on their computer.

For more information check out section 4 of the tutorial which covers randomisation:

> **[Sonic Pi - Tutorial](https://sonic-pi.net/tutorial.html#section-4)**
>
> Sonic Pi Tutorial - Learn how to code music.

---

<div class="post-metadata">

**Author:** ![Taxicletter](https://avatars.discourse-cdn.com/v4/letter/t/7ab992/32.png) [@Taxicletter](https://in-thread.sonic-pi.net/u/Taxicletter)\
**Post date:** [June 22, 2020, 8:23am UTC](https://in-thread.sonic-pi.net/t/randomisation-rand-rrand-choose/4100/5 "2020-06-22T08:23:18Z")

</div>

Thank you all.

I _am_ reading the tutorial, I just wasn’t sure what the difference between _rand_ and _rrand_ was. I thought maybe “rand” was truly random.  
But the difference is the kind of numbers it returns, rrand includes 0 and rand doesn’t. Both floats.

I’m not convinced of the usefulness of this pseudorandomness, but once I start coding maybe it becomes clear. I’m sure it is well thought out :-).

Thanks again. While proceding to read the tutorial, I will come back here for questions (one question more sensible than the other).
