码迷,mamicode.com
首页 > 其他好文 > 详细

随机数的产生

时间:2017-08-14 10:06:26      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:srand   signed   rand   unsigned   and   turn   algorithm   blog   null   

 1 #include<cstdio>
 2 #include<ctime>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     srand(unsigned(time(NULL)));
 8     int n = rand() % 50 + 1;
 9     printf ("%d\n",n);
10     return 0;
11 }

a+rand()%b    a为区间起始点,b为区间长度

随机数的产生

标签:srand   signed   rand   unsigned   and   turn   algorithm   blog   null   

原文地址:http://www.cnblogs.com/hss-521/p/7355904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!