I am currently working on code that generates random numbers on a 4 by 4 board. I have a board.h, board.cpp and a main.cpp file. In main.cpp I include Board.h
.
In Board.cpp
is where I construct the board using rand();
. In main
I create two instances of the class where I get the two boards
My issue is that if I use srand((unsigned int)time(NULL))
in main I'll generate the same two different boards. Whereas if I use srand((unsigned int)time(NULL))
in Board.cpp
I get two identical boards. One solution I've found is sleeping for a second, but I am losing a lot of time by doing that and wanted to know if there's a better solution.