Share variables between live loops

I’m doing my first experiments with Sonic Pi, so fun!
I’m trying to write two live loops, each plays a random note in a chord (say, x and y). I want to make sure the two loops don’t “collide” (for example abs(x-y) should not be less or equal to 1). How to share information between the two loops?

I suppose I could generate before a long array of random pairs of numbers that satisfy my requirement but I was wondering if there is another way in general to share info between loops.


HI Patrick
I’m sure you’ll find Sonic Pi a lot of fun!
To share data between live loops you can use the set and get methods


x = :c4
set :storedx,x

In the second loop you can have


to read the value set in the first loop.
The symbol name given to store the value is not important as long as it is unique. e.g. you could use :x here instead of :storedx


Thanks @robin.newman