Dice roller

Hi,
I have made a simple dice roller, however each time i run the code it always comes up with the same number, how do i avoid this?
The code is:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <cstdlib>

int main()
{
	int d20;
	d20 = (rand() % 20)+1;
	std::cout << d20;
	
	return 0;
}
You need to initialize the pseudo-random number generator. See here:
http://www.cplusplus.com/reference/clibrary/cstdlib/srand/
Awesome, I used the time as my seed. What other things could be used instead though?
Anything that changes frequently and (preferably) doesn't often repeat any values should work.
time() is almost universally used because it fulfills both criteria.
Other time-based functions work well too (like the lower bits of rdtsc), but time(0) is portable.
Topic archived. No new replies allowed.