惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - i.Posei

一个文本管理工具 VNC快速教程 号外号外,国内不用代理能访问facebook了。 - i.Posei 翻译:做好iPhone程序的10点建议 推荐一本书《我编程,我快乐》 【翻译】找到iPhone内存泄露:Leaks工具指引 “网聊依赖症”七大症状 IPHelper(IP切换助手) 谷歌手机地图支持三角基站定位 短信群发 for Pocket PC v1.31 Build 81109 发布啦。 短信群发 for Pocket PC v1.2 版正式发布 《短信群发 v1.1》新鲜出炉啦~~~~~~~ 一个小游戏:数独(Sudoku) 两种获取灰度图像的方法 发现MSDN上的一个错误 发布一个web service,可以通过ISBN获得图书的一些基本信息! 最近做了一个小站,大家评评! We swap it! 今天发现一个以前写的管理代码片段的程序,把源码发出来! 小知识,大应用--正交向量在CDMA中的运用
简单快速的洗牌算法
i.Posei · 2008-02-14 · via 博客园 - i.Posei

过年的时候跟朋友学了一种新的扑克牌玩法,有瘾了,在网上找了半天没找到这种玩法的单机版,于是决定自己写一个。

洗牌当然就成了第一个要完成的动作了,在网上找了一下,找到一篇园子里一位朋友写的文章(扑克牌的随机发牌程序),看看后,感觉有点麻烦,于是自己写了一个,实在是简单,就不多做解释了。代码如下:

    class Poker
    {
        /// <summary>
        /// 记录54张牌
        /// </summary>
 
        private int[] _cards = new int[54] { 0, 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, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
       
        public Poker()
        { }

        public void Reshuffle()
        {
            Random ram = new Random();
            int currentIndex;
            int tempValue;

            for (int i = 0; i < 54; i++)
            {
                currentIndex = ram.Next(0, 54 - i);
                tempValue = _cards[currentIndex];
                _cards[currentIndex] = _cards[53 - i];
                _cards[53 - i] = tempValue;
            }
        }
    }

执行Reshuffle()方法后,_cards里的顺序便是新的了。

PS:在文章里怎么添加代码呢?搞忘记了哦,哪位兄弟告诉一声。