Random Seed in PIC18F

我是研究僧i 提交于 2020-01-04 15:17:28

问题


I'm going to run modified DES code(C language) on the PIC18F2550 microcontroller. For this I am using mplabx IDE v 2 and Mplab xc8 v 1.30.

To modify the code, I need a random number so that each run will produce different numbers.

I want to use the rand function but I need a good seed for Srand function!

Good seed can be time, but since there is no such thing as a micro or I do not know!!


回答1:


You can store an integer value in EEPROM. When the device boots, you use it as a seed and then increment and store it again so that at every reboot you will have a different seed, producing a different sequence for each run. That should be enough for what you want.

If you need something a little more sofisticated, you can try this 555+ADC random seed circuit.



来源:https://stackoverflow.com/questions/22284025/random-seed-in-pic18f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!