//输出0-15的数字
#include <iostream>
#include <string>
using namespace std;
//更好的办法是使用数组来存储 方便索引 循环
void test01()
{srand(time(0));int t0 = 0;int t1 = 0;int t2 = 0;int t3 = 0;int t4 = 0;int t5 = 0;int t6 = 0;int t7 = 0;int t8 = 0;int t9 = 0;int t10 = 0;int t11 = 0;int t12 = 0;int t13 = 0;int t14 = 0;int t15 = 0;for (size_t i = 0; i < 500000000; i++){int a = rand() % 16;if (a == 0){t0++;}if (a == 1){t1++;}if (a == 2){t2++;}if (a == 3){t3++;}if (a == 4){t4++;}if (a == 5){t5++;}if (a == 6){t6++;}if (a == 7){t7++;}if (a == 8){t8++;}if (a == 9){t9++;}if (a == 10){t10++;}if (a == 11){t11++;}if (a == 12){t12++;}if (a == 13){t13++;}if (a == 14){t14++;}if (a == 15){t15++;}}cout << t0 << " "<<t1 << " " << t2 << " " << t3 << " " << t4 << " " << t5 << " " << t6 << " " << t7 << " " << t8 << " " << t9 << " " << t10 << " " << t11 << " " << t12 << " " << t13 << " " << t14 << " " << t15;
}int main()
{test01();return 0;
}
输出结果: