[C #] Helper Package--Randomhelper

Source: Internet
Author: User

Tag: eal specifies a random number greater than Rand sealed next ble return

A random number is often needed in the project, especially a helper class, with the code as follows

usingSystem;2  3 namespacewen.helpers4 { 5     /// <summary> 6     ///Random Number Helper 7     /// </summary> 8      Public Sealed classRandomhelper9     {Ten         /// <summary> One         ///Character Set (remove 0oO of these easily confusing characters) A         /// </summary> -         Private Const stringCharSet ="[Email protected]#$%^&* () _+|" ; -  the         Private Static ReadOnlyRandom random =NewRandom (); -  -         #regionNext -  +         /// <summary> -         ///return non-negative random number +         /// </summary> A         /// <returns>32-bit signed integer greater than or equal to zero and less than System.Int32.MaxValue</returns> at          Public Static intNext () -         { -             returnRandom.next (); -         } -  -         /// <summary> in         ///returns a random number in a specified range -         /// </summary> to         /// <param name= "MaxValue" >The upper limit of the random number to generate (the maximum value cannot be taken by the random number). MaxValue must be greater than or equal to zero</param> +         /// <returns> -         ///A 32-bit signed integer that is greater than or equal to zero and less than MaxValue, that is, the range of the return value typically includes 0 but excludes MaxValue. However, if MaxValue equals zero, then MaxValue is returned.  the         /// </returns> *          Public Static intNext (intmaxValue) $         {Panax Notoginseng             returnRandom.next (maxValue); -         } the  +         /// <summary> A         ///returns a random number in a specified range the         /// </summary> +         /// <param name= "MinValue" >The lower bound of the returned random number (the random number is preferable to the nether value)</param> -         /// <param name= "MaxValue" >The upper bound of the returned random number (the random number cannot take the upper bound value). MaxValue must be greater than or equal to MinValue</param> $         /// <returns> $         ///A 32-bit signed integer greater than or equal to minValue and less than MaxValue, that is: the range of values returned includes MinValue but not maxValue.  -         ///if MinValue equals MaxValue, the MinValue is returned.  -         /// </returns> the          Public Static intNext (intMinValue,intmaxValue) -         {Wuyi             returnRandom.next (MinValue, maxValue); the         } -  Wu         #endregionNext -  About         /// <summary> $         ///returns a random number between 0.0 and 1.0 -         /// </summary> -         /// <returns>double-precision floating-point number greater than or equal to 0.0 and less than 1.0</returns> -          Public Static Doublenextdouble () A         { +             returnrandom.nextdouble (); the         } -  $         /// <summary> the         ///returns a random string the         /// </summary> the         /// <param name= "Length" >string Length</param> the         /// <returns></returns> -          Public Static stringNextstring (intlength) in         { the             vararr =New Char[length]; the  About              for(vari =0; i < length; i++) the             { the                 varindex =Random.next (charset.length); theArr[i] =Charset[index]; +             } -  the             return string. Join ("", arr);Bayi         } the     } the}

[C #] Helper Package--Randomhelper

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.