主页 > 编程资料 > C# >
发布时间:2015-09-26 作者:网络 阅读:222次


using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Security.Cryptography;

namespace randnumber
...{
     class randnumber
    ...{
        /**//// <summary>
        /// 产生随机数的个数
        /// </summary>
         public  int num;
         /**//// <summary>
         /// 随机数存储的数组
         /// </summary>
         public double[] randnum;

         /**//// <summary>
         /// 构造函数
         /// </summary>
          public  randnumber(int num)
         ...{
             this.num = num;
             randnum = new double[this.num];
         }


         /**//// <summary>
         /// 产生随机数,填充数组
         /// </summary>
         /// <returns>产生0--1之间的随机数,填充数组</returns>
         private     void  RundoubleRandoms(Random randObj )
        ...{
           
            
             for (int i=0; i < num; i++)
               ...{
                   randnum[i] = randObj.NextDouble();
                
               }
              
                
        }
        /**//// <summary>
        /// 利用系统时间产生随机数
        /// </summary>
        /// <remarks>调用RundoubleRandoms方法填充数组</remarks>
        public    void  AutoSeedRandoms()
         ...{
                        
             Random autoRand = new Random();

             RundoubleRandoms(autoRand);
         }

         /**//// <summary>
         /// 产生一串随机的密码串
         /// </summary>
         public  string GetRandomPassword(int length)
         ...{
             byte[] random = new Byte[length / 2];
             RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
             rng.GetNonZeroBytes(random);

             StringBuilder sb = new StringBuilder(length);

             for (int i = 0; i < random.Length; i++)
             ...{
                 sb.Append(String.Format("{0:X2}", random[i]));
             }
             return sb.ToString();
         }

    }
}

 

 

这其中包含一个用。net中的密码生成创建一个随机的密码串


 

关键字词: