I’ve been trying to figure out a way that I can cpp progressively slow down loop for a dice program I want to write. Getting a random number and displaying/comparing it is not difficult. My issue is trying to figure out how I could display random numbers as if the dice was rolling where it progressively gets slower and slower until I want to display the rand number that was generated.
I’ve thought about doing a for-loop inside another for-loop and using the first loops number to subtract from the second. I don’t know if there is a better way or not. All seraching comes up with seraches on how a program is going slower because they weren’t allocating memory.
for (int i = 5; i > 0; i--)
{
for (int j = 1000; j > 0; j -= i)
{
cout << randNumGen();
}
}
http://en.cppreference.com/w/cpp/thread/sleep_for
http://en.cppreference.com/w/cpp/chrono
it is probably also worth your while look at C++11 random it is more C++ way of generating random number in a cross platform way.
http://en.cppreference.com/w/cpp/numeric/random
You will need to compile with c++11 support for gcc and clang this is -std=c++0x