def test_lfsr():
    p = 0b101
    seed = 0b100
    mylfsr = lfsr.LFSR(p, seed)
    assert mylfsr.nbits == 3
    data = [mylfsr.cycle() for _ in range(7 * 2)]
    assert data == [0, 0, 1, 1, 1, 0, 1] * 2
Example #2
0
import lfsr

rng = lfsr.LFSR(14, "fib", [0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1])
k = rng.generate_output_stream()
k = k.tolist()
lmao = {}
prev_k = k[0]
ct = 0
total = 0
for i in k[1::]:
    if i != prev_k:
        total += 1
        if (ct + 1 not in lmao.keys()):
            lmao[ct + 1] = 1
        else:
            lmao[ct + 1] += 1
        ct = 0
        prev_k = i
    else:
        ct += 1

for i in sorted(list(lmao.keys())):
    print(i, lmao[i])
print(total)
Example #3
0
            return
        self.visitInorderSubtree(f, node.left)
        f(node.key)
        self.visitInorderSubtree(f, node.right)


def printKey(key):
    print key,


def usage():
    print "Usage: bst <numkeys>"


if __name__ == "__main__":
    import sys, lfsr
    if len(sys.argv) != 2:
        usage()
        sys.exit(1)

    bst = BST()
    lfsr = lfsr.LFSR()
    for i in range(0, int(sys.argv[1])):
        bst.insert(lfsr.randInt())

    print "Size:", bst.size()
    print "Depth:", bst.depth()
    print "Range:", bst.minKey(), "-", bst.maxKey()
    print "Values:",
    bst.visitInorder(printKey)
Example #4
0
import lfsr
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np

rnglol = lfsr.LFSR(14, "fib", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1])
a = rnglol.generate_output_stream()
a = a.tolist()
a.append(0)
print(len(a))
print(a.count(1))
print(a.count(0))
plt.imsave('filename.png', np.array(a).reshape(128, 128), cmap=cm.gray)