Arduino Time Library

I am trying to seed srand() with something random, to get a more random result, so I tried using the C++ #include <ctime.h> library. The compiler said there was no such library, so I downloaded the Arduino #include <Time.h> library, but the compiler gave me errors with that, too. The errors the compiler gave me are below. Can someone help me decipher the errors on the time.h one? Also, what library and command should I use to seed srand()? Compiler error are attached below.

srand(time(NULL));

Compiler_Error_Time.txt (51.5 KB)

Compiler_Errors_ctime.txt (3.8 KB)

1 Like

The time library is not going to provide you with anything that is useful to seed srand. If you do need to use it for something else try

#include <TimeLib.h>

The usual way to try to get something quasi-random for a seed is to read the voltage on an analog input that is not connected to anything.

 srand(analogRead(A0));

Pete

1 Like

The errors the compiler gave me are below. Can someone help me decipher the errors on the time.h one?

What part of the message is difficult to understand?

error: variable 'monthStr1' must be const in order to be put into read-only section by means of 'attribute((progmem))'

Have you googled the message? Is adding const in the declaration that difficult?