问题
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