// This calculates parity on the selected bits (mask = 0xb4).
if(random_byte & 0x80)
sum = 1;
if(random_byte & 0x20)
sum ^= 1;
if(random_byte & 0x10)
sum ^= 1;
if(random_byte & 0x04)
sum ^= 1;
random_byte <<= 1;
random_byte |= sum;
return(random_byte);
}
void srand(char seed) {
random_byte = seed;
}
I want wondering if it is possible to generate a number between a specific range? Say for example, I want a random number between 0-20, is this possible, or do I have to keep generating random numbers until I find one which is in range?
Regards,
James
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Feb 07, 2011 8:30 pm
That function was posted in the early years of the compiler, before CCS
added the standard rand() function. You don't need to use it now.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum