下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
#if 1#include <stdlib.h>#include <stdio.h>#include <time.h>#include <iostream>#include <fstream>using namespace std;int main(){ int nRandNumber[10]; for (int IDx = 0; IDx < 10; ++IDx) { nRandNumber[IDx] = rand();//取随机数范围为integer 0 ~ RAND_MAX(32767) cout << nRandNumber[IDx] << endl; } for (int IDx = 0; IDx < 10; ++IDx) { nRandNumber[IDx] = (double)rand() / (RAND_MAX + 1) * (125 - 35) + 35;//取数35到125之间 cout << nRandNumber[IDx] << endl; } cout << RAND_MAX << endl;//最大值是32767 //srand是一个随机数种子产生函数,当参数为1时,所得到的随机数序列一样 //output : nRanNum1 : 41 nRanNum2 : 18467 // nRanNum3 : 41 nRanNum4 : 18467 ofstream outfile("d:\out.txt"); srand(1); int nRanNum1 = rand(); int nRanNum2 = rand(); cout << "nRanNum1 : " << nRanNum1 << " nRanNum2 : " << nRanNum2 << endl; outfile << "nRanNum1 : " << nRanNum1 << " nRanNum2 : " << nRanNum2 << endl; srand(1); int nRanNum3 = rand(); int nRanNum4 = rand(); cout << "nRanNum3 : " << nRanNum3 << " nRanNum4 : " << nRanNum4 << endl; outfile << "nRanNum3 : " << nRanNum3 << " nRanNum4 : " << nRanNum4 << endl; system("pause"); return 1; }#endif
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的C语言中随机函数发生器rand()用法举例全部内容,希望文章能够帮你解决C语言中随机函数发生器rand()用法举例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)