I'm writing my own method to generate a random number with C as follows:
int randomNumber(){
int catch = *pCOUNTER;
int temp = catch;
temp /= 10;
temp *= 10;
return (catch - temp);
}
pCounter
is basically a pointer to a register in the device I'm using. The number in that register is always increasing so my idea is to take the first digit only.
At some point, the number returned becomes larger than 9 and I'm not sure if the problem is in my code or the device itself. The device is an Altera DE1 board.
Can anyone please help with that?
Thanks!
To achieve what you're trying to do in your code:
int catch = *pCOUNTER;
return (catch % 10); // Returns only the ones digit
However, I question if this approach is anywhere close to being reasonably random...