Inverse rand

hey there,

wondering if someone can help me out with this.. i believe rand works by generating a random number string that can be applied to something, but is not truly random in the sense that a random number is picked each for each value each time a value is called.

in practice this means, if i have # pan rand applied in two places in my code they will "randomly" pan together/in sync.
what i'm looking for is a way to invert one of those values. so in practice one would pan right when the other pans left, by equal amounts.

what's the best way to go about this?

it's a common practice to use a function like @kindohm's shrand.

let shrand x = (x ~>) $ rand 

you'll just put any old number in the x placeholder and the cycle will get shifted so that it generates a different random value

cool. let me see if i understand what this does correctly... this adds x (let's say 1) to each number generated by the rand function? i'm assuming i delete that x after let shrand (that's the only way i could get it to work for me.

not quite. x is the number of cycles shifted so you can grab a new random value that's different from the one currently running on the pattern you don't want it to be shared with. the x value is kind of not important. it could be 1, it could be 10,000; what's important is that it's grabbing the rand value of some future cycle.

ok, thanks for the explanation!
if i'm understanding correctly then that would ensure you get a different set of random numbers, for whatever has shrand applied to it.
so -- what would be the best way to get the inverse value of the rand i have applied somewhere in my code so far?

oh, ok, i see you are trying to do something quite specific with the panning. i thought you were just looking for a workaround to the not-quite-random rand...if i were you, i'd test out some of the continuous patterns like saw and isaw to sync up your pans.

will look into it. cheers for the help!

i can’t try this but right now but range 1 0 $ rand might be what you’re looking for? or possibly (1 - rand)


Yes I think either would work!

1 Like

indeed, both worked like a charm!