#include <stdio.h> //默认 printf等
#include <stdlib.h> //随机数
#include <string.h> //字符串操作函数
#include <sys/time.h> // time()
int mt_rand(int, int);
int main(void) {
int arr[10000][2]={0};
srand(time(0));
for (int i = 0; i < 10000; ++i) {
int num = mt_rand(1,100);
arr[num-1][0]=num;
arr[num-1][1]++;
}
for (int j = 0; j <100 ; ++j) {
printf("随机数字:%d,随机次数:%d \n",arr[j][0],arr[j][1]);
}
return 0;
}
/**
* 根据区间随机
* @param start
* @param end
* @return
*/
int mt_rand(int start, int end) {
return rand() % (end + 1 - start) + start; /*生成一个[start,end)区间内的整数*/
}
本文为仙士可原创文章,转载无需和我联系,但请注明来自仙士可博客www.php20.cn