用函数写的产生随机数,糊里糊涂的不知道对不对?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int a[5]={0,1,2,3,4},i, b,m;
main()//shuffle 洗牌;licensing 发牌;
{
int shuffle();
shuffle();
for (i=0;i<5;i++)
printf("%d\n",a[i]);
}
shuffle()
{
srand (time(0));
m=rand();
for (i=0;i<5;i++) //洗牌程序
{
b=a[i]; //互换
a[i]=a[m%(5-i)+i];
a[m%(5-i)+i]=b;
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int a[5]={0,1,2,3,4},i, b,m;
int main()//shuffle 洗牌;licensing 发牌;
{
int* shuffle();
int *arr = shuffle();
for (i=0;i<5;i++)
printf("%d\n",*arr++);
return 0;
}
int* shuffle()
{
srand (time(0));
for (i=0;i<5;i++) //洗牌程序
{
m = rand()%(5-i)+i;
int tmp=0;
tmp = a[i];
a[i] = a[m];
a[m] = tmp;
}
return a;
}