#include <thread>
#include <chrono>
:::
for (int i = 5; i > 0; i--)
{
for (int j = 1000; j > 0; j -= i)
{
cout << randNumGen();
std::this_thread::sleep_for(
std::chrono::milliseconds(j));
}
}
http://en.cppreference.com/w/cpp/thread/sleep_for
http://en.cppreference.com/w/cpp/chrono
看看 C++11 random 可能也是值得的,它更像是 C++ 以跨平台方式生成随机数的方式。
std::uniform_int_distribution<int> distribution(1, 6); //dice values
std::mt19937 engine; // Mersenne twister MT19937
int random = distribution(engine);
http://en.cppreference.com/w/cpp/numeric/random
#include <thread>
#include <chrono>
#include <random>
#include <iostream>
:::
std::random_device rd;
std::uniform_int_distribution<int> dist(1, 6); //dice values
std::mt19937 mt(rd()); // Mersenne twister MT19937
for (int i = 5; i > 0; i--) //i don't really get what your loops mean
{
for (int j = 1000; j > 0; j -= i)
{
cout << dist(mt);
std::this_thread::sleep_for(
std::chrono::milliseconds(j));
}
}
您需要使用对 gcc 和 clang 的 c++11 支持进行编译,这是 -std=c++0x