【1】扑克牌洗牌算法: ********************************************* 函数名:void get_rand_number(int array[],int length) 功能:随机交换数组中位置,达到洗牌目的 备注:全局洗牌:value = rand()%length; 局部洗牌:value = index+rand()%length; 注意:rand()函数可取0~375555. ********************************************* #include <iostream> using namespace std; void get_rand_number(int array[],int length); void main() { int array [] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, 25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,45,46,47, 48,49,50,51,52}; int length = sizeof(array)/sizeof(int); get_rand_number(array,length); for (int i = 0;i<length;i++) { cout<<array[i]<<" "; if (i>0&&i%12==0) { cout<<endl; } } } void get_rand_number(int array[],int length) { int index; int value; int median; if (NULL==array||0==length) { return; } for (index=0;index<length;index++) { value = rand()%length; median = array[index]; array[index] = array[value]; array[value] = median; } }