How do I generate random numbers in a microcontroller efficiently?

前端 未结 8 2081
梦毁少年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:03

    If you have access to an ADC, then you can read the least significant bit from it, and use it as a seed for a Pseudo Random Number Generator, like others have posted. Obviously you will need to read more than one bit from the ADC, so multiple reads are needed, which could take a while. But you only need to do this once, at startup for example, and then use faster PRNG to generate new random numbers.

    Many embeded devices have built inn ADC, for example the ATMega family form Atmel.

提交回复
热议问题