The following code outputs a random number each second:
int main () { srand(time(NULL)); // Seeds number generator with execution time. while (true)
If you are using C++ and are concerned about good distribution you can use TR1 C++11 .
#include std::random_device rseed; std::mt19937 rgen(rseed()); // mersenne_twister std::uniform_int_distribution idist(0,100); // [0,100] std::cout << idist(rgen) << std::endl;