Created
March 12, 2017 11:41
-
-
Save aniline/1131649713d933f067e1d110a0677899 to your computer and use it in GitHub Desktop.
Some trials with lfsr.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, time | |
id = 1234567890 | |
lfsr = 0xDEADBEEF | |
def lfsrN(lfsr, count): | |
#0b10101010101 | |
#0x80000417, 0b10000000 00000000 0000 0100 0001 0111 | |
for n in range(1, count): | |
# To check.. Is it reeaaaly correct ? | |
bit = ((lfsr >> 0) ^ (lfsr >> 1) ^ (lfsr >> 2) ^ (lfsr >> 4) ^ (lfsr >> 10) ^ (lfsr >> 31)) & 1; | |
lfsr = (lfsr >> 1) | ((((lfsr >> 31) ^ bit) & 1) << 31) | |
return lfsr | |
# python lfsr.py> /tmp/x; gnuplot -p -e "plot for [col=2:3] '/tmp/x' using col title columnheader" | |
print 'i r band' | |
for n in range(1, 500): | |
lfsr = lfsrN((id+lfsr+n) & 0xFFFFFFFF, 32); | |
# lfsr = (id+lfsr+n) & 0xFFFFFFFF | |
prn = lfsr & 0xFF | |
print n, prn, 100+(prn % 51) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment