首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-04-14 
C# 游戏点卡 批量生成 怎么实现?C# 游戏点卡 批量生成点卡面值:30元/50元/100元卡号:是全数字点卡密码是:

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);        } 

热点排行