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