C/C++编程产生指定范围内的随机数,直接上个小程序:
#include <stdlib.h> // 对应于C++中cstdlib #include <time.h> // ctime #include <stdio.h> int main() { srand(time(NULL)); int low = 0, high = 100; int rnum = rand() % (high - low + 1) + low; printf("random number = %d\n", rnum); system("pause"); return 0; }