转载于:https://blog.csdn.net/garfielder007/article/details/51386490
C/C++编程产生指定范围内的随机数,直接上个小程序:
-
#include
// 对应于C++中cstdlib
-
#include
// ctime
-
#include
-
-
int main()
-
{
-
s
rand(time(
NULL));
-
int low =
0, high =
100;
-
int rnum = rand() % (high - low +
1) + low;
-
printf(
"random number = %d\n", rnum);
-
system(
"pause");
-
return
0;
-
}