I'm using Xcode as my IDE on macOS for some simple pure-C code. The code uses stdlib's rand
. A former thread here suggested calling rand
twice near the start of main
to better randomize it. So I added this code:
// seed the random with the provided number or randomize it based on the time
if (random_seed > -1)
srand(random_seed);
else
srand((unsigned int)time(NULL) | (getpid() << 8));
// now call rand to prime the pump
double pump = rand();
pump = rand();
This causes clang to complain that "Value stored to 'pump' during its initialization is never read", which is the entire point. I thought I could fix this by:
rand();
rand();
But then I get the complaint that "Return value of function rand() is not used". So I need to do something with the value to suppress the message(s).
Is there a way to fix this in code? It's been used on macOS, Win and Linuxen, so I'd like to avoid anything clang/Xcode/mac-ish or using the pre-processor. Is there some canonical method in C?