github.com/status-im/status-go@v1.1.0/protocol/identity/alias/flfsr.go (about) 1 package alias 2 3 // For details: https://en.wikipedia.org/wiki/Linear-feedback_shift_register 4 type LSFR struct { 5 data uint64 6 poly uint64 7 } 8 9 func newLSFR(poly uint64, seed uint64) *LSFR { 10 return &LSFR{data: seed, poly: poly} 11 } 12 13 func (f *LSFR) next() uint64 { 14 var bit uint64 15 var i uint64 16 17 for i = 0; i < 64; i++ { 18 if f.poly&(1<<i) != 0 { 19 bit ^= (f.data >> i) 20 } 21 } 22 bit &= 0x01 23 24 f.data = (f.data << 1) | bit 25 26 return f.data 27 }