Important changes to questions
We’re making some changes to Mbed Questions. From 10th December 2019 this site will be archived and new questions should be asked on our new forum site. Until that date you can continue to reply to existing questions here but can’t ask new questions.
1 year, 9 months 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
You need to log in to post a question