C++随机数

#include <iostream>
#include <ctime> #include <cstdlib> using namespace std; int main() { //使用时间做种子,每次产生随机数不一样 int start = 5, end = 15; srand(unsigned(time(NULL))); for(int i = 0;i < 10;i++)//产生10个5-15之间的随机数 { cout << int(start + (end - start)*rand()/(RAND_MAX +1.0)) << endl; } return 0; }

 

posted @ 2018-08-12 16:42  SuenDanny  阅读(110)  评论(0编辑  收藏  举报