效果如下
5C8H1I8w
5O4L4V6Y
8I1V6O1x
5q5i0l8z
3U8B1a6f
2q0h0h8p
8d0X6p8I
7Q5l7R1Q
1O4w1k5w
2O6N2r5L
8m4p4n1x
0D1W4X3e
3U6U8K0G
2V2F7C7v
1f2X6H6y
2l3j1m5I
0T3J1w6Z
4E3E7M6Q
3f0q6A5l
3T7z1G2N
程序
#include <stdio.h>
#include <time.h>
#include <string.h>
const int MAX = 9;
const int MIN = 0;
char RandString()
{
int j = rand()%2;
char temp;
int m = 0;
if( j==0 )
temp ='a';
else
temp='A';
m = rand()%26;
temp = temp + m;
return temp;
}
int main( void )
{
long i = 0,j;
char cTemp[9];
FILE *fp = NULL;
srand(time(NULL));
fp = fopen("random2.txt", "w");
for(; i<16; i++){
j = i%8;
if (i%2 == 0)
cTemp[j] = (rand() % (MAX-MIN)+MIN)+'0';
else
cTemp[j] = RandString();
if (j==7)
{
cTemp[8] = '\n';
fputs(cTemp,fp);
printf("%s",cTemp);
}
}
fclose(fp);
return 0;
}