Examples of C # random array data in asp.net

Source: Internet
Author: User
Tags datetime

Random array data, random int digits, random string code

#region   Stochastic Services       /// <summary>        ///  random sequencing of the business       //        ///  08-10-24       /// </summary>        /// <param name= "List" ></param>       /// < Returns></returns>       private static List< Maticsoft.model.tb_ap> getrandomschemelist (list<maticsoft.model.tb_ap> list)        {          List<

maticsoft.model.tb_ap> bulist = list;           maticsoft.model.tb_ap[] bulisttemp =  new maticsoft.model.tb_ap[list. count];            int[] temp = getrandomunrepeatarray (0, bulist.count - 1,

 bulist.count);           for  (int i = 0; i  < temp. length; i++)           {     

         BuListtemp[i] = BuList[temp[i]];           }         

  bulist.clear ();

          bulist.addrange (BuListtemp);

          return BuList;       }        /// <summary>        ///  Random number       /// </summary> &nbsP;     public static random random = new random ();       /// <summary>       ///  int  Numerical value       /// </summary>       of random non-duplication  /// <param name= "MinValue" ></param>       ///  <param name= "MaxValue" ></param>       /// <param 

Name= "Count" ></param>       /// <returns></returns>       public static int[] getrandomunrepeatarray (int  Minvalue, int maxvalue, int count)       {   

       //random rnd = new random ();           int length = maxValue - minValue + 1;           byte[] keys = new byte[length]

;           random.

Nextbytes (keys);

          int[] items = new int[length];           for  (int i = 0; i  < length; i++)           {   

           items[i] = i + minValue;           }         

  array.sort (Keys, items);

          return items;     &nbsP;&NBSP}        #endregion 


Example 2

   private static int rep = 0;         //         ///  Generate a random number string        ///         ///   Number of digits to be generated        ///  generated numeric string          public static string generatecheckcodenum (Int codecount)         {           string str  = string.
Empty;            long num2 = 
datetime.now.ticks + rep;
           rep++;            Random random = new  Random (((int) ((ULONG) num2) &NBSP;&AMP;&NBSP;0XFFFFFFFFL)  |  ((int) (NUM2&NBSP;&GT;&GT;&NBSP;REP));            for  (int i = 0; i  < codecount; i++)            {                int num =  Random.
Next ();                str = str  +  ((char) (0x30 +  (ushort) (NUM&NBSP;%&NBSP;10))).
ToString ();            }        
    return str;        }          ///  Generate Random letter strings (digital alphabet mixes)        ///            Number of digits to be generated        ///  the generated letter string        public static string  Generatecheckcode (int codecount)        {            string str = string.
Empty;            long num2 = 
datetime.now.ticks + rep;
           rep++;            Random random = new 
Random (((int) ((ULONG) num2) &NBSP;&AMP;&NBSP;0XFFFFFFFFL))  |  ((int) (NUM2&NBSP;&GT;&GT;&NBSP;REP));            for  (int i = 0; i  < codecount; i++)            {                char ch;                int num =  random.
Next ();                if  (num % &NBSP;2)                 == 0)  {                 
  ch =  (char) (0x30 +  (ushort) (num % 10));                }                 else                 {                    ch =  (char) (0x41 +  ((ushort) (num % 0x1a));                }                 str = str + ch.
ToString ();            }        
    return str;        }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.