Skip to content

Instantly share code, notes, and snippets.

@Darfk
Created June 29, 2014 07:56
Show Gist options
  • Save Darfk/67645bf76fc689103766 to your computer and use it in GitHub Desktop.
Save Darfk/67645bf76fc689103766 to your computer and use it in GitHub Desktop.
Linear Feedback Shift Register
package lfsr
import (
)
type LFSR struct {
buf int32
}
func NewLFSR() (r *LFSR) {
r = new(LFSR)
r.buf = 5;
return
}
func (r* LFSR) Read(p []byte) (n int, err error) {
n = 0
err = nil
for ; n < len(p); n++ {
p[n] = byte(r.buf)
r.buf = r.buf >> 1
r.buf += ((r.buf & 1) << 31) ^ ((r.buf & 4) << 29)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment