#include
#include
#include
void main()
{
int i,j;
FILE *fp;
fp=fopen("random1.txt","w");
if(fp==NULL)
printf("不能打开文件\n");
srand((unsigned)time(NULL));
for(i=0;i<100;i++)
{
j=rand()%100;
if(j<25) //6到10的25%
{
j=rand()%10;
while(j<6)
j=rand()%10;
fprintf(fp,"%d ",j);
}
else if(j<75) //11到14的50%
{
j=rand()%15;
while(j<10)
j=rand()%15;
fprintf(fp,"%d ",j);
}
else //15到18的25%
{
j=rand()%19;
while(j<15)
j=rand()%19;
fprintf(fp,"%d ",j);
}
printf("%d\t",j);
}
}
新建一个random1.txt就可以了