/// /// Helper class for generating random values /// public static class RandomHelper { private static Random randomSeed = new Random(); public static string RandomString(int size, bool lowerCase) { // StringBuilder is faster than using strings (+=) StringBuilder RandStr = new StringBuilder(size); // Ascii start position (65 = A / 97 = a) int Start = (lowerCase) ? 97 : 65; // Add random chars for (int i = 0; i < size; i++) RandStr.Append((char)(26 * randomSeed.NextDouble() + Start)); return RandStr.ToString(); } public static int RandomNumber(int Minimal, int Maximal) { return randomSeed.Next(Minimal, Maximal); } public static bool RandomBool() { return (randomSeed.NextDouble() > 0.5); } public static System.Drawing.Color RandomColor() { return System.Drawing.Color.FromArgb( randomSeed.Next(256), randomSeed.Next(256), randomSeed.Next(256) ); } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|