线性反馈移位寄存器甚至不杂散

时间:2018-09-27 11:50:05

标签: distribution uniform-distribution lfsr

我确实根据以下文档为布尔数组中的线性feedbackpack移位寄存器编写了一个非常简单的类似于C的代码:

http://courses.cse.tamu.edu/walker/csce680/lfsr_table.pdf https://www.xilinx.com/support/documentation/application_notes/xapp052.pdf

n = 63

代码:

#include <stdio.h>
#include <stdint.h>
#include <math.h>

int main() {
    bool lfsr[63] = {true};

    const int iterations = 16384 * 8;
    int deviation = 0;

    ///*
    for(int bit = 0; bit <= 62; bit++) {
        int x = 0, y = 0;

        for(int j = 0; j < iterations; j++) {
            bool feedback = lfsr[62] ^ lfsr[61];

            for(int k = 62; k >= 1; k--)
                lfsr[k] = lfsr[k - 1];

            lfsr[0] = feedback;

            if(lfsr[bit])
                x++;
            else
                y++;
        }

        deviation += y - x;

        printf("bit %d \t= %d <-> %d (deviation: %d)\r\n", bit, y, x, y - x);
    }

    printf("Total deviation: %d\r\n", deviation);
}

结果:

bit 2   = 76565 <-> 54507 (deviation: 22058)
bit 3   = 68863 <-> 62209 (deviation: 6654)
...
bit 58  = 65636 <-> 65436 (deviation: 200)
bit 59  = 65155 <-> 65917 (deviation: -762)
bit 60  = 65030 <-> 66042 (deviation: -1012)
bit 61  = 65654 <-> 65418 (deviation: 236)
bit 62  = 64667 <-> 66405 (deviation: -1738)
Total deviation: 306364

重点是,正如您所看到的,分布几乎不均匀/均匀。实际上,偏差对我而言太高了。

我是否犯了一个错误或者关于LFSR我不知道某些事情?

0 个答案:

没有答案