为什么此伪随机数生成器(LFSR)的输出如此可预测? [英] Why are the outputs of this pseudo random number generator (LFSR) so predictable?

查看:257
本文介绍了为什么此伪随机数生成器(LFSR)的输出如此可预测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我在这里问如何在硬件中生成随机数,并被告知要使用LFSR.它将是随机的,但将在一定值后开始重复.

Recently I asked here, how to generate random numbers in hardware and was told to use an LFSR. It will be random but will start repeating after a certain value.

问题在于所生成的随机数非常可预测,因此可以很容易地猜出下一个值.例如,检查以下模拟:

The problem is that the random numbers generated are so predictable that the next value can be easily guessed. For example check the simulation below:

可以通过将前一个数字加上自己的+1来猜测下一个随机"数字.有人可以验证这是否正常并且可以预期吗.

The next "random" number can be guessed by adding the previous number with a +1 of itself. Can someone please verify if this is normal and to be expected.

这是我用于LFSR的代码:

Here is the code I used for the LFSR:

    module LFSR(
    input clock,
    input reset,
     output [12:0] rnd 
    );

wire feedback = rnd[12] ^ rnd[3] ^ rnd[2] ^ rnd[0]; 

reg [12:0] random;

always @ (posedge clock or posedge reset)
begin
    if (reset)
        random <= 13'hF; //An LFSR cannot have an all 0 state, thus reset to FF
    else
        random <= {random[11:0], feedback}; //shift left the xor'd every posedge clock
end

assign rnd = random;

endmodule

要从此处进行XOR的位的位置:表第5页

The location of the bits to XOR are picked up from here: The table page 5

推荐答案

LFSR每个时钟仅生成一个随机位.它不会在每个周期生成一个新的(对于您而言)13位数字. rnd中的其他12位只是旧的随机值,因此不会显得非常随机.

LFSR only generates one random bit per clock. It doesn't generate a new (in your case) 13-bit number each cycle. The other 12 bits in rnd are just the old random values, so it will not appear very random.

如果需要13位随机数,则必须每13个周期对LFSR进行一次采样,或者将13个LFSR与不同的种子并行放置,并使用13个零位作为您的随机数.

If you need a 13-bit random number, then you must either sample LFSR every 13 cycles, or put 13 LFSR in parallel with different seeds, and use the 13 zero bits as your random number.

这篇关于为什么此伪随机数生成器(LFSR)的输出如此可预测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆