随机数的产生

 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为区间长度

posted @ 2017-08-14 08:35  ⊙∽⊙Perseverance  阅读(132)  评论(0编辑  收藏  举报