Pseudo random number generator Tutorial

This tutorial is now hosted here 






Comments

  1. I have to do a VHDL program:

    Build a generator of pseudo-random numbers with the period 15.The polynomial generating this sequence is 1 + v + v ^ 4.The display will be on digit.Use the internal clock of FPGA.

    board: basys 3 artix 7

    ReplyDelete
    Replies
    1. In the examples I did I used XNOR feedback. You may want to read the Wikipedia entry that explains how to generate the polynomial using XOR - https://en.wikipedia.org/wiki/Linear-feedback_shift_register.

      Delete
  2. Hi - nice blog.

    Just wanted to add that LFSR are not pseudo random number generators, they are pseudo random bit generators

    If you are using them to generate n-bit random numbers you should advance the LFSR 'n' times, to generate n new bits. This avoids the sequence being 'randomly' having n(x+1) = 2*n(x)+1 or n(x+1) = 2*n(x).

    Also, because of the way that LFRSs have only 2^n-1 states, (which isn't made clear in the blog) there is a slight bias in the generated bits (which may or may not be significant, depending on your use case.

    ReplyDelete
    Replies
    1. Hi Mike, thanks!

      Thanks also for your insight on how to use the LFSR to produce random numbers instead of bits. I will take this into account to improve the tutorial.

      Delete
  3. The length is a generated sequence is not 2^n, it is 2^n-1, but only if the polynomial is a generating polynomial. As you can see in your waveform, the signal 'count' never reaches x"F".

    Why are you using such a big construct to stop the simulation? 'simend' is a signal, so you can write just "wait until (simend = '1'); assert ....; wait;". Because 'simend' has no other purpose, you could also just wait for the specified time.

    Nevertheless, a good testbench should not end with an assertion, you should either terminate all processes (incl. implicit processes like the clock) or use "std.env.stop" to halt the simulation kernel.

    ReplyDelete
    Replies
    1. Hi Patrick,

      Thanks for all the comments you have left. I really appreciate the time you have invested for that. So from your and Mike's inputs I understand I have to make a major upgrade to this tutorial. I hope I will be able to make it soon.

      Regards,

      Delete
    2. Also I have corrected to 2^n-1 as you correctly pointed out.

      Delete

Post a Comment

Popular posts from this blog

Xilinx AXI Stream tutorial - Part 1

Analysis, elaboration and synthesis