双色球生成类

using System;

 

namespace Random

{

     /// <summary>

     ///目的: 为了响应公司同事刘大侠中双色球彩票的要求,而写的生成一个随机序列数字的类.

     ///时间:2005-07-04

     ///编写人:房客

     ///版本:V1.0.0

     ///更多精彩请登陆我的Blog:http://www.cnblogs.com/sxlfybb/

     /// </summary>

     public class Random

     {

         /// <summary>

         /// 静态类主入口和出口

         /// </summary>

         /// <param name="NumberS">生成的位数设置</param>

         /// <param name="NumberCount">要生成的总数</param>     

         /// <returns>输入结果</returns>

         public static string GetRandomNumber(int NumberS,int NumberCount)

         {

              System.Random myRandom = new System.Random(DateTime.Now.Millisecond);

 

              int[] intNum = new int[NumberS];

              int intTemp = 0;

              string strResult = "";

 

              for (int i = 0;i<NumberS;i++)

              {

                   do

                   {

                       intTemp = myRandom.Next(1,NumberCount);

                   }

                   while(isInclue( ref intNum,intTemp));

                  

              }

 

              Array.Sort(intNum);

 

              for (int k=0;k<intNum.Length;k++)

              {

                   strResult += intNum[k].ToString() + "  ";

              }

              return strResult;

         }

 

         /// <summary>

         /// 检查数组中是否已经包含此int

         /// </summary>

         /// <param name="intNum"></param>

         /// <param name="intTemp"></param>

         /// <returns></returns>

         public static bool isInclue(ref int[] intNum,int intTemp)

         {

              if ( Array.IndexOf(intNum,intTemp) <0 )

              {

                   for( int m=0;m<intNum.Length;m++)

                   {

                       if (intNum[m] == 0)

                       {

                            intNum[m] = intTemp;

                            return true;

                       }

                   }

              }

              return false;

         }

     }

}

 

posted on 2005-07-04 14:57  房客  阅读(450)  评论(0编辑  收藏  举报

导航