How do I generate random numbers in a microcontroller efficiently?

前端 未结 8 2055
梦毁少年i
梦毁少年i 2021-02-15 18:14

How do I generate random numbers in a microcontroller efficiently? Are there any general guidelines or a particular fast method?

8条回答
  •  我在风中等你
    2021-02-15 19:06

    Pseudo random number generators that are the fastest and least demanding w.r.t. the instruction set (only shift and xor, no multiplication or division) are smaller variants of the Mersenne twister idea (called Generalized Linear Feedback Shift register). Mersenne twister itself needs too much memory for microcontrollers.

    The problem with these generators is that they may generate long sequences near zero if you are unlucky. With a reasonable size of the state space and initialization from another PNRG this is however unlikely.

    They are also not secure for cryptography or gambling, an intelligent adversary can predict future states after observing the output. This is because they are linear.

    I once designed such a generator for a small nonstandard processor with a state space of about 50 24-bit words. I tested variants with the Diehard test suite until I found a good one. The application was generating random variations for a hardware test.

提交回复
热议问题