I am working on a secure LoRa transmission, where I need to generate the same pseudo-random number on the transmitter and the receiver (it would be part of the encryption algorithm) based on an input counter. So this function should give the same output for a given input, just like a hashing algorithm.
As an example here is what I mean, but as you can see the computation gets longer based on the input:
unsigned int f(unsigned int input) {
srand(1234);
for (unsigned int i = 0; i < input; i++) {
rand();
}
return rand();
}
Is there a more efficient way to do this? I am on an ESP32 microcontroller.
edit. Thanks for all the answers. I could have accomplished what I was trying to do with a CRC function, but as per your recommendation I ended up ditching this approach and used a standard encryption algorithm instead.