27
« on: July 15, 2010, 07:24:21 PM »
Mark,
For our case we need the seed value to be more random than just between chips, we need it to be more random on each power cycle.
Also we are mostly concerned with using the random value for network traffic stuff. So here is what I did. It's much more random, but does rely on network traffic. So a project that doesn't use networking will not benefit from this method.
In NetworkIndicators.c declare an unsigned short randomSeed and in the EMAC_RX_INTERRUPT case:
ACTIVITY_LED_ON(); // turn on activity LED (for a short time)
randomSeed = (randomSeed * randomSeed) + 1;// start forming a random seed, based on local network traffic.
then in fnRandom() add:
register unsigned short usShifter = usRandomNumber; // for speed, copy to register
if (!usShifter) {
if(randomSeed){
usShifter = randomSeed;
}else{
usShifter = 0x127b; //should never happen, but just in case
}
}
}
lastly I stubbed out fnInitialiseRND() to just return 0.
This method works pretty well. The first time fnInitialiseRND() is called, randomSeed is still zero, but by the time fnRandom() is called for the first time, there has been some network traffic and randomSeed now has some 16 bit number.
Aaron