I am trying to find a c function that generates a 32bit random/pseudo random number and can be reproduced. (Like the rand/srand functions). I cannot use urandom because I cannot reproduce the sequence like I can with srand/rand. Do I have to write my own function or does something like this already exist?
Thanks
For future reference, while the suggestions by others were good. I ended up by doing something like this:
uint32_t generateRandom (unsigned int randomSeed) {
uint32_t number = 0;
int randomNumber, x;
for (x=0; x<8;x++) {
randomNumber = rand_r(&randomSeed) % 16;
number |= (randomNumber<<(x*4));
randomSeed++;
}
return (number);
}
Join 2 (or more)
rand()results to obtain as many digits as you need.Bad (because it’s exaggerated) example: