I'm making a library to create a simple IV byte array for encrypting data.
Here is my code:
#include "ivgenerator.h"
void generateRandomIV(uint8_t iv[], int ivSize) {
for (int i = 0; i < ivSize; i++) {
iv[i] = random(1, 256);
}
}
Now I get the build error ivgenerator.c:3:23: error: unknown type name 'uint8_t'
Okey, I can fix that by including Arduino.h:
#include <Arduino.h>
#include "ivgenerator.h"
void generateRandomIV(uint8_t iv[], int ivSize) {
for (int i = 0; i < ivSize; i++) {
iv[i] = random(1, 256);
}
}
But now I get the error ivgenerator.c:6:17: error: too many arguments to function 'random'
Arduino docs (https://www.arduino.cc/reference/en/language/functions/random-numbers/random/) aren't great but my usage should be correct. It returns a long
i simply could cast since I'm forcing a span.
But the error is too many arguments. I could change it to random() but then I would get a long in return.
Whats going on here, and how can I rectify so I'm able to generate a "random" number between 1 and 256?