随机数生成

          for (int j = 0; j < 8; j++)
                    {
                        String charOrNum = ran.Next(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字 
                        if (charOrNum=="char") // 字符串 
                        {
                            int choice = ran.Next(2) % 2 == 0 ? 65 : 97; //取得大写字母还是小写字母 
                            val += (char)(choice + ran.Next(26));
                        }
                        else // 数字 
                        {
                            val += ran.Next(10).ToString();
                        }
                    }

posted on 2011-07-21 12:41  jameshappy  阅读(204)  评论(0编辑  收藏  举报