2 years ago.

time(0) returns -1?

So my friend is currently writing a program which uses a random numbers, and is using srand(time(0)) to get rand() to function as expected. It was working fine, however he deleted and rewrote a good deal of it, and it suddenly wasn't returning random results. After several attempts to debug, I had him print out what time(0)'s value was 4 times. I expected these values to be 0 because the mBed's clock was malfunctioning for whatever reason, but I was quite shocked to see that it was outputting -1 each time. I'm not even slightly aware how that would be possible. Is this a malfunction of the hardware setup or is it a problem with the code somehow not calling time(0) correctly. I've also tried time(NULL) and the same thing happened.

I'm so confused

Be the first to answer this question.