以下是引用神vLinux飘飘在2006-7-1 22:53:45的发言:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define TIMES 1000
#define CARD_NUMBER 54
int main(void){
int card[CARD_NUMBER],i,a,b,temp;
time_t t;
srand( (unsigned)time(&t) );
for(i=0;i<CARD_NUMBER;card[i]=i++);
for(i=0;i<TIMES;i++){
temp = card[a=rand()%CARD_NUMBER];
card[a] = card[b=rand()%CARD_NUMBER];
card[b] = temp;
}
for(i=0;i<CARD_NUMBER;i++)
printf("card[%d]=%d\t",i,card[i]);
printf("\n");
return 0;
}
晕,理论上没错,但是实践中却出了错啊,希望你来了看到贴后自己运行一下,我不知道是我的机子问题还是怎么,card的值居然是负数,而且全是一样的!!!!