简体   繁体   English

用于FPGA的Verilog中的1024位伪随机发生器

[英]1024 bit pseudo random generator in verilog for FPGA

I want to generate random vectors of length 1024 in verilog . 我想在verilog中生成长度为1024的随机向量。 I have looked at certain implementations like Tausworth generators and Mersenne Twisters. 我看过某些实现,例如Tausworth生成器和Mersenne Twisters。 Most Mersenne twisters have 32 bit/ 64 bit outputs . 大多数Mersenne扭曲器具有32位/ 64位输出。 I want to simulate an error pattern of 1024 bits with some probability p . 我想模拟一个概率为p的1024位错误模式。 So , I generate a 32 bit random number (uniformly distributed) using Mersenne Twister. 因此,我使用Mersenne Twister生成了一个32位随机数(均匀分布)。 Since I have 32 bit random numbers , this number will be in the range 0 to 2^32-1 . 由于我有32位随机数,因此该数字的范围为0到2 ^ 32-1。 After this I set the number to 1, if the number generated from this 32 bit value is less than p*(2^32-1) .Otherwise the number is mapped to a 0 in my 1023 bit vector . 之后,如果从这个32位值生成的数字小于p *(2 ^ 32-1),则将数字设置为1,否则该数字将映射到我的1023位向量中的0。 Basically , each 32 bit number is used to generate a bit in the 1023 vector according to the probabilistic distribution . 基本上,每个32位数字用于根据概率分布在1023向量中生成一个位。

The above method implies that I need 1024 clock cycles to generate each 1024 bit vector. 上面的方法暗示我需要1024个时钟周期来生成每个1024位向量。 Is there any other way which allows me to do this quickly ? 还有其他方法可以让我快速执行此操作吗? I understand that I could use several instance of the Mersenne Twister in parallel using different seed values but I was afraid that those numbers will not be truly random and that there will be collisions . 我知道我可以使用不同的种子值并行使用多个Mersenne Twister实例,但是我担心这些数字不会真正是随机的,并且会发生冲突。 Is there something that I am doing wrong or something that I am missing ? 是否有我做错的事情或缺少的事情? I would really appreciate your help 我将衷心感谢您的帮助

Okay, So I read a bit about Mersenne Twisters in general from wikipedia . 好的,所以我从Wikipedia上大致了解了有关Mersenne Twisters的内容。 I accept I did't outright get all of it but I got this: Given a seed value (to initialise the array), the module generates 32 bit random numbers. 我接受我并没有完全理解所有这些,但是我得到了:给定种子值(用于初始化数组),模块将生成32位随机数。

Now, from your description above, it takes one cycle to compute one random number. 现在,根据上面的描述,计算一个随机数需要一个周期。

So your problem basically boils to to it's mathematics rather than being about verilog as such. 因此,您的问题基本上归结为数学问题,而不是像verilog这样。

I would try to explain the math of it as best as I can. 我会尽力解释它的数学原理。

You have a 32 bit uniformly distributed random number. 您有一个32位均匀分布的随机数。 So, the probability of any one bit being high or low is exactly (well, close to, cause psuedo random) 0.5 . 因此,任一位的highlow的概率恰好是0.5 (很好,接近,导致伪随机)。

Let's forget that this is a pseudo random generator, because that is the best you are going to get(So let's consider this as our ideal). 让我们忘记这是一个伪随机生成器,因为那是您将获得的最佳效果(因此,将其视为我们的理想选择)。

Even if we generate 5 numbers one after the other, the probability of each one being any particular number is still uniformly distributed. 即使我们一个接一个地生成5个数字,每个数字都是任意特定数字的概率仍然是均匀分布的。 So if we concatenate these five numbers, we will get a 160 bit completely random number. 因此,如果将这五个数字连接起来,我们将得到一个160位完全随机的数字。


If it's still not clear, consider this way. 如果仍然不清楚,请考虑这种方式。

I'm gonna break the problem down. 我要解决这个问题。 Let's say we have a 4-bit random number generator (RNG), and we require 16 bit random numbers. 假设我们有一个4位随机数生成器(RNG),而我们需要16位随机数。

Each output of the RNG would be a hex digit with a uniform probability distribution. RNG的每个输出将是具有均匀概率分布的十六进制数字。 So the probability of getting some particular digit (say... A) is 1/16 . 因此,获得某个特定数字(例如A)的概率为1/16 Now I want to make a 4 digit Hex number (say... 0xA019). 现在,我想输入一个4位数的十六进制数字(例如... 0xA019)​​。

Probability of getting A as the Most Significant digit = 1/16 将A作为最高有效位的概率= 1/16

Probability of getting 0 as digit number 2 = 1/16 将0作为数字2的概率= 1/16

Probability of getting 1 as digit number 3 = 1/16 将1用作数字3的概率= 1/16

Probability of getting 9 as the Least Significant digit = 1/16 获得9作为最低有效位的概率= 1/16

So the probability of getting 0xA019 = 1/(2^16) . 因此获得0xA019 = 1/(2^16)的概率。 Infact, probability of getting any four digit hex number would be exactly the same. 实际上,获得任何四位数十六进制数字的可能性将完全相同。 Now, extend the same logic to Base-32 Number systems with 32 digit numbers as the required output and you have your solution. 现在,将相同的逻辑扩展到具有32位数字的Base-32 Number系统作为所需的输出,您便有了解决方案。


So, we see, we could do with just 32 repetitions of the Mersenne twister to get the 1024 bit output (that would take 32 cycles, still kinda slow). 因此,我们看到,我们可以只重复32次Mersenne扭曲器即可获得1024位输出(这将花费32个周期,仍然有点慢)。 What you could also do is synthesise 32 twisters in parallel (that would give you the output in one stroke but would be very heavy on the fpga in terms of area, power constraints). 您还可以做的是并行地合成32个捻线机(这将使您一冲程获得输出,但就面积,功率限制而言,fpga将会非常繁琐)。

The best way to go about this would be to try for some middle ground (maybe 4 parallel twisters running in 8 cycles). 解决此问题的最佳方法是尝试一些中间立场(也许是4个平行的捻线机以8个周期运行)。 This would really be a question of the end application of the module and the power and timing constraints that you need for that application. 这实际上是一个问题,即模块的最终应用以及该应用所需的功率和时序约束。

As for giving different seed values, most PRNGs usually have provision for input seeds just to increase randomness, from what I read on Mersenne Twisters, it has the same case. 至于给出不同的种子值,大多数PRNG通常提供输入种子的目的只是为了增加随机性,根据我在Mersenne Twisters上的阅读,情况相同。

Hope that answers your question. 希望这能回答你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM