一个textbox 输入0-9999的之间的数值 譬如 输入5的话就产生
如下规则的数。
16字元有可能為英文(區分大小寫)或數字
序號內必需包含 “英文大寫”、“英文小寫”、”數字”以上三種元素當中的至少二種
序號的號碼與順序不能完全一樣急呀。。

解决方案 »

  1.   

    是不是做成Office的那种注册号啊。
    好像也不是啊,那个是固定长度的。
      

  2.   

    难道很难么?不就是取一些随机数,然后通过char拼凑一个string出来么?
      

  3.   

    一个textbox 输入0-9999的之间的数值 譬如 输入5的话就产生 
    这句话不懂,是否意思为:
    if(textbox.Text="5")
      //就产生$%^#$^#$*&(&*))#%@#@!的。
      

  4.   

    其实就像csdn的验证码  它是5位的  有数字有子母  谁也不知道字母或者数字在第几位。都是随机出来的。
    区别的就是我的要16位 并且每4位隔开咯
      

  5.   

    不知道怎么随即生成大小写的字母,用swith弄了个,只有a-f6个字母的楼主看下,可以的话自己加case吧
    期待高手给出好方法  private string suijishu()
            {
                Random ro=new Random ();
                string result = "";
                for (int i = 0; i < 16; i++)
                {
                    if (i>0&&i % 4 == 0)
                        result += "-";
                    switch (ro.Next(1, 7))
                    {
                        case 1:
                            result += "a";
                            break;
                        case 2:
                            result += "b";
                            break;
                        case 3:
                            result += "c";
                            break;
                        case 4:
                            result += "d";
                            break;
                        case 5:
                            result += "e";
                            break;
                        case 6:
                            result += "f";
                            break;
                    }
                }            
                return result; 
            }
      

  6.   

    private static char[] constant = { '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', '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' };     [WebMethod(Description="得到数字加英文的随机数,参数:随机数长度,返回值:一个字符串!")]
         public string pxkt_GetCharFont(int strLength)
         {
              System.Text.StringBuilder    newRandom    =    new    System.Text.StringBuilder(62);   
             Random    rd=    new    Random();   
             for(int    i=0;i<strLength;i++)   
             {   
               newRandom.Append(constant[rd.Next(62)]);   
             }   
             return    newRandom.ToString();   
         }
      

  7.   

            private string CreateRandomNum()
            {
                string result = "";
                #region 生成随机号
                for (int i = 0; i < 16; i++)
                {
                    Random myRandom1 = new Random((int)DateTime.Now.Ticks);
                    System.Threading.Thread.Sleep(10);
                    int kinds = myRandom1.Next(0, 3);
                    switch (kinds)
                    {
                        case 0://数字类
                            #region 数字
                            Random myRandom11 = new Random((int)DateTime.Now.Ticks);
                            System.Threading.Thread.Sleep(10);
                            int number11 = myRandom11.Next(0, 9);
                            result += number11.ToString();
                            continue;
                            #endregion
                        case 1://大写字母类
                            #region 大写字母类
                            Random myRandom22 = new Random((int)DateTime.Now.Ticks);
                            System.Threading.Thread.Sleep(10);
                            int number22 = myRandom22.Next(65, 90);
                            result += Convert.ToChar(number22).ToString();
                            continue;
                            #endregion
                        case 2://小写字母类
                            #region 小写字母类
                            Random myRandom33 = new Random((int)DateTime.Now.Ticks);
                            System.Threading.Thread.Sleep(10);
                            int number33 = myRandom33.Next(97, 122);
                            result += Convert.ToChar(number33).ToString();
                            continue;
                            #endregion
                        default: break;
                    }
                }
                #endregion
                #region 加"-"
                string newstring="";
                for (int i = 1; i <= result.Length; i++)
                {
                    newstring+=result[i-1];
                    if (i % 4 == 0 && i != result.Length)
                        newstring += "-";
                }
                result = newstring;
                #endregion
                return result;
            }刚写的随机数如你所说:数字,大,小写字母,都有。
      

  8.   

    linjf520  
    谢谢  我试试
      

  9.   

    这么快就出来了,再送一个简单点的
    public class Main {    public static void main(String[] args) throws Exception {
            Main m = new Main();        int max_count = 10;//产生序列个数
             int count =max_count;
            Vector<String> l=new Vector();
            char[]ckeys=new char[max_count];
            while(count>0){
                char [] c = m.getKey();
                String s=new String(c);
                System.out.println(""+s);
                if(m.checkKey(c)&&!l.contains(s)){//l.contains(s)检查重复序列
                    l.add(new String(c));
                    count--;
                }
            }
            for(int i=0;i<l.size();i++){//打印
                System.out.println(""+l.get(i));
            }    }
        static char[] hc = {'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', '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'};    char[] getKey() {//得到随机序列
            char k[] = new char[16];
            for (int i = 0; i < 16; i++) {
                int ind = ((int)( Math.random() * 100000)) % 62;
                k[i] = hc[ind];
            }
            return k;
        }    boolean checkKey(char[] c) {//检查是否是合格的序列
            boolean Nu = true, ABC = true, abc = true;
            byte ct = 0;
            for (int i = 0; i < 16; i++) {
                if (Nu && '0' <= c[i] && c[i] >= '9') {
                    Nu = false;
                    ct++;
                }
                if (abc && 'a' <= c[i] && c[i] >= 'z') {
                    abc = false;
                    ct++;
                }
                if (ABC && 'A' <= c[i] && c[i] >= 'Z') {
                    ABC = false;
                    ct++;
                }
                if (ct > 1) {
                    return true;
                }
            }
            return false;
        }
    }
      

  10.   

    直接在窗体里加个textbox和button控件,双击button控控(给该控件加个单击事件)
    private void button_click(object sender,eveargs e)
    {
     this.textbox.text=CreateRandomNum();
    }就可以测试了。
      

  11.   

    private static char[] constant = { '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', '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' };
            int xiaoxiecanshu = 0;
            int daxiecanshu = 0;
            int shuzicanshu = 0;
             private string suijishu()
            {
                Random ro=new Random ();
                string result = "";            
                for (int i = 0; i < 16; i++)
                {
                    if (i>0&&i % 4 == 0)
                        result += "-";                              
                    if(ro.Next(0, 62)<26)
                        xiaoxiecanshu++;
                    else if(ro.Next(0,62)>35)
                        daxiecanshu++;
                    else
                        shuzicanshu++;
                    result += constant[ro.Next(0, 62)];
                }
                int canshu = 0;
                if (daxiecanshu > 0)
                    canshu++;
                if (xiaoxiecanshu > 0)
                    canshu++;
                if (shuzicanshu > 0)
                    canshu++;
                if (canshu > 1)
                    return result;
                else
                    return "";
            }
      

  12.   

    忘记这里是C#的了,把Vector换成换成链表类型就可以了