Last edited on
In this case, why would it ever be a good idea to let the user seed the pseudo-random number generator? Just seed via time and you'll be good to go.

If you insist on using rand and srand found in <cstdlib> as opposed to the C++11 <random> header, you should at least wrap your pseudo-random number generation in a function:
1
2
3
4
5
6
7
8
9
10
int random(int min, int max) {

	static bool isSeeded = false;
	if (!isSeeded) {
		isSeeded = true;
		::srand(::time(0));
	}

	return (::rand() % (max - min + 1) + min);
}
Last edited on
Topic archived. No new replies allowed.