日期:2014-05-18  浏览次数:21050 次

数组的字符串怎么随机组合
C# code

string[] orders = new string[]{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", 
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", 
"r", "s", "t", "u", "v", "w", "x", "y", "z"};



大虾们,请问怎么让6个字符串随机组合?

------解决方案--------------------
这个问题 算法可以解决的 
利用高中排列组合知识
------解决方案--------------------
全排列组合算法,网上搜去,有
------解决方案--------------------
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);
        }

------解决方案--------------------
SQL code

--发个SQL SERVER 版本的
declare @sql varchar(6) set @sql=''

select top 6 @sql=@sql+char(number) from master..spt_values 
where number between 48 and 57 or number between 97 and 122
and type='p' order by newid()

select @sql
go 10

/*
60xrya
dvs01k
zkbgt6
f4siwr
8gihc9
gw3kdq
hg4q18
ng0p8f
o7dnfa
d1vx9q
*/

------解决方案--------------------
探讨
C# code

string[] orders = new string[]{ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
"r", "s", "t", "u", "……