洗牌!!!随机数序列~!

原创 2013年12月05日 01:12:04
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 54

void PokerShuffle(int a[],int n)
{
	int r,i;
	srand(time(NULL));
    for (i=1;i<=n;)
    {
        r = rand()%n;		
        if (a[r] == 0)
			a[r]=i++;
    }
	for(i=0;i<n;i++)
		a[i]-=1;
}

int main(void)
{
	char c,j,a[][7]={"大鬼  ","小鬼  ",
		"红桃A ","红桃K ","红桃Q ","红桃J ","红桃10","红桃9 ",
        "红桃8 ","红桃7 ","红桃6 ","红桃5 ","红桃4 ","红桃3 ","红桃2 ",
		"黑桃A ","黑桃K ","黑桃Q ","黑桃J ","黑桃10","黑桃9 ",
        "黑桃8 ","黑桃7 ","黑桃6 ","黑桃5 ","黑桃4 ","黑桃3 ","黑桃2 ",
		"方块A ","方块K ","方块Q ","方块J ","方块10","方块9 ",
        "方块8 ","方块7 ","方块6 ","方块5 ","方块4 ","方块3 ","方块2 ",
		"草花A ","草花K ","草花Q ","草花J ","草花10","草花9 ",
        "草花8 ","草花7 ","草花6 ","草花5 ","草花4 ","草花3 ","草花2 "};
	
    int b[N] = {0} ;
    
	PokerShuffle(b,N);

	for(j=0;j<N;j++)
		printf("%s ",a[b[j]]);
	printf("\n");

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。原帖:http://blog.csdn.net/pjwonline1

相关文章推荐

【Java】利用Collections类下的shuffle洗牌方法改进在一定的范围内产生不重复的随机数

上次在《【Java】在一定的范围内产生不同的随机数》(点击打开链接)上所提到的方法,尽管已经解决了一定范围内产生不同随机数的问题,运行速度已经可以的,至少不会弄很久都弄不好,其实利用Collectio...

C语言洗牌

  • 2015-03-30 23:22
  • 16KB
  • 下载

扑克牌洗牌程序

  • 2013-04-30 12:11
  • 38KB
  • 下载

C#--第七周实验--任务5--编写一个控制台应用,实现输出一个从1开始到511*511长度的随机数序列

/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. *...

流、文件拷贝、序列化、随机数、DecimalForamt、Calendar、SimpleDateFormat

流、文件拷贝、序列化、随机数、DecimalForamt、Calendar、SimpleDateFormat
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)