Hello,
To further clarify the possible use of a CRC algorithm to generate a quasi-random value, I found the following code to generate an 8-bit CRC value.
/* Update 8-bit CRC value
using polynomial X^8 + X^5 + X^4 + 1 */
#define POLYVAL 0x8C
void update_crc(unsigned char new, unsigned char *crc)
{
unsigned char c, i;
c = *crc;
for (i = 0; i < 8; i++) {
if ((c ^ new) & 1) c = (c >> 1 ) ^ POLYVAL;
else c >>= 1;
new >>= 1;
}
*crc = c;
}
To use this function to generate a quasi-random value, I think the following would work -
Firstlly, define and initialise a global variable to contain the random value
unsigned char rndval = SEED; // Must be non-zero value
Then when the next random value is required, and rndval is to be updated, use the following code -
update_crc(0xFF, &rndval);
My understanding is that the first parameter could actually be any non-zero constant.
Regards,
Mac
Message Edited by bigmac on 2007-03-0112:49 PM