当前位置: 代码迷 >> ASP.NET >> C# 游戏点卡 批量生成 如何实现
  详细解决方案

C# 游戏点卡 批量生成 如何实现

热度:8626   发布时间:2013-02-25 00:00:00.0
C# 游戏点卡 批量生成 怎么实现?
C# 游戏点卡 批量生成 
点卡面值:30元/50元/100元 
卡号:是全数字
点卡密码是:字母+数字

该怎么生成?怎么批量生成这些唯一随机点卡带不同面值的



------解决方案--------------------------------------------------------
C# code
  private string GetRandomCode()        {            char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };            string code = string.Empty;            for (int i = 0; i < 4; i++)            {                Random rnd = new Random(GetRandomSeed());                code += chars[rnd.Next(0, 10)].ToString();            }            return code;        }        private int GetRandomSeed()        {            byte[] bytes = new byte[4];            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();            rng.GetBytes(bytes);            return BitConverter.ToInt32(bytes, 0);        }
------解决方案--------------------------------------------------------

看看注释
C# code
   private string GetRandomCode()        {            char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };  //随机数范围,填上字母就会生成字母            string code = string.Empty;            for (int i = 0; i < 4; i++) //4是生成多少位的随机数,自己可以改            {                Random rnd = new Random(GetRandomSeed());                code += chars[rnd.Next(0, 10)].ToString();            }            return code;        }        private int GetRandomSeed()        {            byte[] bytes = new byte[4];            System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();            rng.GetBytes(bytes);            return BitConverter.ToInt32(bytes, 0);        }
  相关解决方案