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); 10 return 0; 11 }
a+rand()%b a为区间起始点,b为区间长度