I have a random number generator that runs in constant time.
The prototype for this function is as follows:
uint8_t rand();
What I want to be able to do is create a function that randomly returns an uint8_t such that the output is between 0 and max where max is the maximum number to be returned. The prototype for such a function would be:
uint8_t randi(uint8_t max);
There are algorithms online to do this and on stack overflow. For example, https://stackoverflow.com/a/6852396/1444313. But my problem is that I want to achieve this in constant time. I can't find any method that does this in constant time.
Additionally i'm running on an ARM Cortex-m0 without hardware division so using the % operator is not possible.
Does anyone have any suggestions or pointers on how I would achieve this in constant time?
Thanks