欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > C ++测试随机数

C ++测试随机数

2025/5/16 3:07:31 来源:https://blog.csdn.net/quaer/article/details/140890956  浏览:    关键词:C ++测试随机数
//输出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;
}

输出结果:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com