#include <stdio.h> #include<stdlib.h> #include<time.h> #define TOP_N 100 int getRand(int n){ srand((unsigned) time(NULL)); return rand() % n + 1; } int main (){ //定义随机数变量,并赋初值 int rand1=getRand(TOP_N); printf("%d",rand1); return 0; }