# Is there a way to "get" random seed?

**URL:** <https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948>\
**Category:** \[P\] Patreon Support\
**Created:** [April 8, 2018, 12:48pm UTC](https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948 "2018-04-08T12:48:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)\
**Post date:** [April 8, 2018, 12:48pm UTC](https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948/1 "2018-04-08T12:48:47Z")

</div>

I have composed a beat which has lots of randomness. By chance this randomness sounds really great. The way the randomness seems to work makes it so it plays consistently the same notes every time I restart the song which is exactly what I want.

The problem is that when I add more live loops to the song it somehow changes the random notes that play, it’s as if the random seed has changed.

I have not used “use\_random\_seed” in my code so I have no idea what this great sounding seed number is. Is there any way I can use “puts” to display it on the screen so I can in turn set the seed to that value with “use\_random\_seed”?

In the meantime it seems that as long as I call my new live\_loops underneath the old live\_loops that use the randomness it doesn’t seem to alter the seed. It’s a bit of a organizational headache since I want these new loops to be up top but I’ll make due for now.

---

<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:** [April 8, 2018, 2:37pm UTC](https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948/2 "2018-04-08T14:37:16Z")

</div>

Hi Baggy,

Sounds like what you are after is ‘current\_random\_seed’,

This can be set via the fns use\_random\_seed and with\_random\_seed.  
It is incremented every time you use the random number generator via  
fns such as choose and rand.’

Although I’ve a feeling when a buffer starts, isn’t the random  
seed = 0?

Perhaps Robin or Sam know better…

Anyways… put it as the first line of your code and see what  
you come up with…

Try this

```ruby
a = current_random_seed
puts rand
puts '============================='
puts rand
puts rand
puts rand
puts '============================='
puts 'Recovering nice random number'
puts '============================='
use_random_seed a
puts rand
puts '============================='          

```

Eli…

---

<div class="post-metadata">

**Author:** ![bagofdragonite](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/bagofdragonite/32/2049_2.png) [@bagofdragonite](https://in-thread.sonic-pi.net/u/bagofdragonite)\
**Post date:** [April 8, 2018, 3:50pm UTC](https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948/3 "2018-04-08T15:50:25Z")

</div>

Thanks. You were right about the random seed being zero. Thats what I suspected too originally. Funnily enough I can’t reproduce this issue I was having before. Now when I add live loops earlier in the code it has no effect on the randomized sequence. I must have been doing something wrong but I have no idea what it could be as I was doing nothing that would have changed the seed from zero… Either way the problem is solved and its good to know about “current\_random\_seed” since it may come in handy later.

---

<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:** [April 22, 2018, 1:43am UTC](https://in-thread.sonic-pi.net/t/is-there-a-way-to-get-random-seed/948/4 "2018-04-22T01:43:56Z")

</div>

#…gypsy…

mn=[];for jn in 1…1024  
mn[jn]=hz\_to\_midi(11\*jn)  
end; mn[0]=:r

c=[5,6,9,5, 5,6,9,9, 5,6,9,5, 8,9,5,5,  
8,5,9,9, 8,5,9,9, 8,5,9,9, 8,9]  
m=[2,3,4,5]; o=[1,2,4]  
rv=[2,0,1,1,2,0,1,1,2,0,1,1,2,0,1,1]  
dm=[1,0,0,0,4,0,0,0,1,0,0,0,2,0,2,0]

sn=[:fm, :pluck, :pretty\_bell]  
pn=[0.0, 1.0, -1.0]  
lv=[1.0, 2, 1]  
rl=[1.0, 1.0, 0.3]

use\_bpm 110  
live\_loop :voice1 do  
for x in 0…29; for y in 0…3; r=rand\_i(3)  
synth sn[r], note: mn[c[x]\*m[y]\*o[r]]-12,  
pan: pn[r], release: rl[r], amp: lv[r]  
sleep 0.5; end; end; end

use\_bpm 55  
live\_loop :pad do  
for x in 0…29  
synth :dsaw, note: mn[c[x]]+12, detune: 7, sustain: 1,  
release: 0, amp: 0.15  
sleep 1; end; end

use\_bpm 440  
live\_loop :percussion do  
for x in 0…15;  
synth :beep, note: mn[24\*dm[x]], release: 0.2  
synth :noise, note:127, release: 0.1,  
amp: rv[x]/3.0  
sleep 1; end; end
