# (Teletype) LFSR op - help with pre-review

Hi, I’ve started implementing an LFSR (linear feedback shift-register) noise/pseudo-random/chaos operator.
It works like a helper, you input a seed, supply the feedback tap (bit), and assign it to some variable.
Of course, you could do this in-script, but it’s cumbersome and also a bit hard to remember the exact syntax.
LFSR’s have really interesting musical properties which is why they were selected by Don Buchla for the source of uncertainty. It is also used in IME’s Zorlon Cannon. A similar, but not quite the same circuit, is used by the turing machine and Malekko/Richter Noisering.

Next you keep supplying that variable so use would be:

INIT (or reset script):
A 1

SCRIPT 1:
A LFSR A 5
CV 1 N & 7 A

You could also do a lot more interesting stuff like:

S1:
A LFSR A 13
IF EZ A: A 1
CV 1 N & 7 A
S2:
A LFSR A 7
IF EZ A: A 1
CV 1 N & 5 A

//The EZ-checks are because, when mixing various tap configurations, you may end up with it reaching a 0-state, that is impossible to get out of.

Now, I haven’t implemented an op or done any TT development before so I would like some pre-review before submitting a PR:
https://github.com/monome/teletype/compare/master...veqtor:LFSR_OP

Another thing I’m thinking about, while we’re on the subject of shift-register based algorithmic composition is, what about a re-circle-ing LSHIFT/RSHIFT op? Something like (python code):
def wrsh(i, b, l):
return ((i >> b) | (i << (l-b))) & ((1 << l) - 1)

def wlsh(i, b, l):
return ((i << b) | (i >> (l-b))) & ((1 << l) - 1)

where i is input and b is shift amount and l is length

This let’s you do some pretty cool stuff like:

IF GT RAND 20 19: A LFSR A 13
ELSE: A WLSH A 1 16

This leads to a sequence that mostly repeats but sometimes changes a little bit

Thoughts?

3 Likes

Anyone? Would like to get some eyes on this…

Cool work! I haven’t vetted the logic (too tired right now), but the code looks clean, and the operator looks useful.

A circular bit shift would be excellent, I agree. Maybe `ROL` or `ROR` for “rotate left” and “rotate right”? AVR32 doesn’t have a 16-bit version of these instructions, but you can absolutely use those instructions by adding 17 (16 extra bits plus carry) to every shift.

Or just do it in C because it’s a million times more understandable

Cool, I will try to setup my build environment and try it out and implement the ROL and ROR ops too

After some reading and thought, it seems like an LFSR would benefit from a slate of pre-defined internal logic rules instead of a single XOR mapping.

Would you be opposed to implementing an internal rule state, a la:

``````LFSR.RULE 3    // select fibonacci
``````

All future calls to `LFSR` would use the fibonacci internal mapping.

I think that would make for a compelling feature.

Maybe, only, I’d rather have this “raw” LFSR available too…
Fibonacci is nice, but with a lot of other LFSR types are more or less “good noise” which I find quite musically uninteresting.